import { projectRef } from "@/lib/projects"; import { refuseCaller } from "@/lib/report/caller"; import { crossSiteRefusal } from "@/lib/report/sameOrigin.mjs"; import { REPORTS_ROOT } from "@/lib/projects/core.mjs"; import { readsGet, readsPost } from "@/lib/report/readsApi.mjs"; import { kickQueue, queueDir, queueRunnerStatus } from "@/lib/queue/runner"; export const dynamic = "force-dynamic"; // A VIDEO's READS (lane reads-find; the Reads page, components/projects/ReadsPanel.tsx): lib/report/readsApi.mjs // answers -- the functions `umtool reads` runs, called directly (never an argv built from what a page typed). // // GET ?project[&find&case=1&word=1&stale=1&character=] the reads (and Find's matches), the queue, the undo // POST {project, op: "preview", from, to, scope: "reads"|"say", case?, word?, only?} // POST {project, op: "replace", from, to, scope, case?, word?, only} (These reads names the previewed reads) // POST {project, op: "undo"} the newest replace (These reads, or an Everywhere) taken back // POST {project, op: "reread", only} the reads counted, queued on the app's queue // POST {project, op: "stop"} · {op: "retry", read} · {op: "pick", which: "new"|"old", only} const headers = { "cache-control": "no-store" }; const ctx = () => ({ reportsRoot: REPORTS_ROOT, queueDir: queueDir(), runner: queueRunnerStatus(), kick: kickQueue }); export async function GET(request: Request) { const url = new URL(request.url); const project = await projectRef(String(url.searchParams.get("project") ?? "")); if (!project) return Response.json({ error: "no such project" }, { status: 404 }); try { return Response.json(await readsGet(project, url.searchParams, ctx()), { headers }); } catch (e) { return Response.json({ error: e instanceof Error ? e.message : String(e) }, { status: 500, headers }); } } export async function POST(request: Request) { const cross = crossSiteRefusal(request.headers); if (cross) return Response.json({ error: cross }, { status: 403 }); const refused = refuseCaller(request, "/api/report/reads"); if (refused) return refused; const b = (await request.json().catch(() => null)) as Record | null; if (!b) return Response.json({ error: "bad json" }, { status: 400 }); const project = await projectRef(String(b.project ?? "")); if (!project) return Response.json({ error: "no such project" }, { status: 404 }); try { const r = await readsPost(project, b, ctx()); return Response.json(r.json, { status: r.status, headers }); } catch (e) { return Response.json({ error: e instanceof Error ? e.message : String(e) }, { status: 500, headers }); } }