first commit

This commit is contained in:
gotolombok
2026-01-31 17:21:32 +08:00
commit f839fbd63a
109 changed files with 19204 additions and 0 deletions

48
lib/history-service.ts Normal file
View File

@@ -0,0 +1,48 @@
import { createClient } from "@/lib/supabase/client";
export const savePlaybackProgress = async ({
subjectId,
type,
title,
poster,
season,
episode,
lastPosition,
duration
}: {
subjectId: string;
type: 'movie' | 'series' | 'dracin';
title: string;
poster: string;
season?: number;
episode?: number;
lastPosition: number;
duration: number;
}) => {
const supabase = createClient();
const { data: { user } } = await supabase.auth.getUser();
if (!user) return;
try {
const { error } = await supabase
.from('history')
.upsert({
user_id: user.id,
subject_id: subjectId,
type,
title,
poster,
season: season || null,
episode: episode || null,
last_position: Math.floor(lastPosition),
duration: Math.floor(duration),
updated_at: new Date().toISOString()
}, {
onConflict: 'user_id,subject_id,type'
});
if (error) console.error("Error saving history:", error);
} catch (e) {
console.error("Save progress error:", e);
}
};