Added updateWatchHistory func
This commit is contained in:
@@ -263,7 +263,24 @@ export async function getKeyValue(key: string): Promise<KeyValue | null> {
|
||||
return (await decryptWithMasterKey(respJson.valueNonce, respJson.valueCipher)) ?? null;
|
||||
}
|
||||
|
||||
export async function saveHistoryToBackend(video: VideoPlay, progress: number = 0) {
|
||||
export async function updateWatchHistory(videoId: string, progress: number) {
|
||||
await sodium.ready;
|
||||
const rawKey = await getRawKey();
|
||||
if (!rawKey) return;
|
||||
|
||||
const videoHash = await getSecureHash(videoId, rawKey);
|
||||
|
||||
await fetch(`/api/user/history/${videoHash}`, {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
body: JSON.stringify({
|
||||
watched: new Date(),
|
||||
progress
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
export async function saveWatchHistory(video: VideoPlay, progress: number = 0) {
|
||||
await sodium.ready;
|
||||
const rawKey = await getRawKey();
|
||||
if (!rawKey) return;
|
||||
@@ -277,6 +294,7 @@ export async function saveHistoryToBackend(video: VideoPlay, progress: number =
|
||||
|
||||
await fetch('/api/user/history', {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
body: JSON.stringify({
|
||||
id: videoHash,
|
||||
watched: new Date(),
|
||||
|
||||
@@ -19,7 +19,7 @@ import { error } from '@sveltejs/kit';
|
||||
import { get } from 'svelte/store';
|
||||
import { _ } from './i18n';
|
||||
import { isOwnBackend } from './shared';
|
||||
import { saveHistoryToBackend } from './api/backend';
|
||||
import { saveWatchHistory } from './api/backend';
|
||||
|
||||
export async function getWatchDetails(videoId: string, url: URL) {
|
||||
const playerStateRetrieved = get(playerState);
|
||||
@@ -49,7 +49,7 @@ export async function getWatchDetails(videoId: string, url: URL) {
|
||||
}
|
||||
|
||||
if (isOwnBackend()?.internalAuth && get(rawMasterKeyStore)) {
|
||||
saveHistoryToBackend(video);
|
||||
saveWatchHistory(video);
|
||||
}
|
||||
|
||||
let comments;
|
||||
|
||||
Reference in New Issue
Block a user