import { projectRef } from "@/lib/projects"; import { editorConfig } from "@/lib/report/fetchWindows.mjs"; import { applyStandIns, restoreStandIn, standInPlan } from "@/lib/report/standIns.mjs"; export const dynamic = "force-dynamic"; // STAND-INS (release 35 O1): the clip deck's "Use stand-in" and "Restore", and // `umtool fallback` from a terminal (lib/report/standIns.mjs for both). A // montage clip whose window the editor refused (fetch-runs.json) and is not on // disk is switched to its instance's first public alternate — on the clip // (`fallbackFrom`), its ruling and voice-match row moved with it — and back. // // GET ?project= the candidates, the switched, the refused with none // POST { project, clips?: [id…] } switch them (every candidate when none are named) // POST { project, restore: } put one back as it was 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 }); try { return Response.json(await standInPlan(project, { cfg: editorConfig() }), { headers }); } catch (e) { return Response.json({ error: e instanceof Error ? e.message : String(e) }, { status: 500, headers }); } } export async function POST(request: Request) { const b = (await request.json().catch(() => null)) as Record | 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 }); try { if (typeof b.restore === "string" && b.restore) { return Response.json({ restored: await restoreStandIn(project, b.restore) }, { headers }); } const clips = Array.isArray(b.clips) ? b.clips.map(String) : null; const res = await applyStandIns(project, { clips, cfg: editorConfig() }); return Response.json({ switched: res.switched, none: res.plan.none }, { headers }); } catch (e) { return Response.json({ error: e instanceof Error ? e.message : String(e) }, { status: 400, headers }); } }