Initial commit

This commit is contained in:
twotalesanimation
2026-06-11 10:46:09 +02:00
commit 81ad7e4ea9
223 changed files with 39530 additions and 0 deletions
+44
View File
@@ -0,0 +1,44 @@
// app/api/watch-history/route.ts
import { NextResponse } from 'next/server';
import { getServerSession } from 'next-auth';
import { authOptions } from '@/lib/auth-options';
import { prisma } from '@/lib/prisma';
export async function GET(req: Request) {
try {
const session = await getServerSession(authOptions);
if (!session?.user?.email)
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
const userEmail = session.user.email;
const user = await prisma.user.findUnique({ where: { email: userEmail } });
if (!user)
return NextResponse.json({ error: 'user not found' }, { status: 404 });
// Fetch all videos watched by user, sorted by most recently updated
const watchHistory = await prisma.videoProgress.findMany({
where: { userId: user.id },
include: {
video: {
select: {
id: true,
title: true,
thumbnail: true,
durationSec: true,
url: true,
},
},
},
orderBy: { updatedAt: 'desc' },
});
return NextResponse.json(watchHistory);
} catch (err: any) {
console.error('watch history GET error', err);
return NextResponse.json(
{ error: err?.message ?? 'server error' },
{ status: 500 }
);
}
}