import { NextResponse } from 'next/server'; import { revalidatePath, revalidateTag } from 'next/cache'; import { getCachedVideoDashboard, VIDEO_COLLECTION_TAG } from '@/entities/video/api/videoCache'; import { addVideo } from '@/entities/video/api/videoRepository'; import { normalizeVideoDraft } from '@/entities/video/model/video'; export const revalidate = 3600; export async function GET() { const dashboard = await getCachedVideoDashboard(); return NextResponse.json(dashboard, { headers: { 'cache-control': 'public, max-age=60, s-maxage=3600, stale-while-revalidate=86400', }, }); } export async function POST(request: Request) { const body = (await request.json().catch(() => undefined)) as | { title?: string; owner?: string; sourceUrl?: string; status?: string } | undefined; const video = await addVideo(normalizeVideoDraft(body ?? {})); revalidateTag(VIDEO_COLLECTION_TAG, { expire: 0 }); revalidatePath('/'); return NextResponse.json({ video }, { status: 201 }); }