import { projectRef } from "@/lib/projects"; import { readManifest } from "@/lib/projects/report.mjs"; import { fixStalePatchMarkers, stalePatchMarkers } from "@/lib/report/patchMarkers.mjs"; import { refuseCaller } from "@/lib/report/caller"; export const dynamic = "force-dynamic"; // A TAKE PATCH'S MARKERS, BACK ON THE CUT (lib/report/patchMarkers.mjs; UI // notes #6). The patch-markers-stale row's "Take the cut's markers", and // `umtool patch-markers --fix`: each marker after a clip // that is not in the cut takes the `after` of the cut's marker with the same // label; one no marker of the cut shares a label with is left, and named. // // GET ?project= every stale patch marker // POST { project, file } settle that patch const headers = { "cache-control": "no-store" }; 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, headers }); const m = await readManifest(project.dir); return Response.json({ stale: m ? await stalePatchMarkers(project.dir, m) : [] }, { headers }); } export async function POST(request: Request) { const refused = refuseCaller(request, "/api/report/patch-markers"); if (refused) return refused; const b = (await request.json().catch(() => null)) as { project?: unknown; file?: unknown } | null; if (!b || typeof b !== "object") return Response.json({ error: "bad json" }, { status: 400, headers }); const project = await projectRef(String(b.project ?? "")); if (!project) return Response.json({ error: "no such project" }, { status: 404, headers }); const m = await readManifest(project.dir); if (!m) return Response.json({ error: "the project has no video.manifest.json" }, { status: 400, headers }); try { const r = await fixStalePatchMarkers(project.dir, m, String(b.file ?? "")); return Response.json({ ok: true, ...r }, { headers }); } catch (e) { return Response.json({ error: e instanceof Error ? e.message : String(e) }, { status: 400, headers }); } }