import { projectRef } from "@/lib/projects"; import { resolveMomentOnFile } from "@/lib/report/moments.mjs"; export const dynamic = "force-dynamic"; // GET ?project=&file=&t=[&duration=] // // What is on screen at `t` of a rendered cut (lib/report/moments.mjs): the // entry, its onscreen title and quote, the source second and its archive link, // and `approx` when the file and the build's schedule disagree. A timed note // stores this at write time. `{ entry: null }` when the file has no schedule // (a preview made without a build) -- the note then keeps `t` alone. export async function GET(request: Request) { const url = new URL(request.url); const project = await projectRef(url.searchParams.get("project") ?? ""); if (!project) return Response.json({ error: "no such project" }, { status: 404 }); const file = url.searchParams.get("file") ?? ""; if (!file || file.startsWith("/") || file.split("/").some((s) => s === ".." || s === "")) { return Response.json({ error: "file must be relative to the project" }, { status: 400 }); } const t = Number(url.searchParams.get("t")); if (!Number.isFinite(t) || t < 0) return Response.json({ error: "t must be seconds ≥ 0" }, { status: 400 }); const d = Number(url.searchParams.get("duration")); const r = await resolveMomentOnFile(project.dir, file, t, Number.isFinite(d) && d > 0 ? d : null); return Response.json(r, { headers: { "cache-control": "no-store" } }); }