Added updateWatchHistory func

This commit is contained in:
WardPearce
2026-02-23 19:21:57 +13:00
parent 739a3f00a1
commit cc0e2e0bf3
2 changed files with 21 additions and 3 deletions
+19 -1
View File
@@ -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(),
+2 -2
View File
@@ -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;