import { readFile } from "node:fs/promises"; import path from "node:path"; import { projectRef } from "@/lib/projects"; import { RENDER_LOG } from "@/lib/report/renderRecord.mjs"; import { isTakeId } from "@/lib/report/takes.mjs"; import { takeRender } from "@/lib/queue/view"; export const dynamic = "force-dynamic"; // A TAKE'S RENDER RECORD (lib/report/renderRecord.mjs), what `umtool take // status` reads: // // GET ?project=&take= the record, resolved (a running one whose // process is gone reads failed), or 404 // GET ?project=&take=&log=1 takes//render.log, FULL, as text 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 take = url.searchParams.get("take"); if (!isTakeId(take)) return Response.json({ error: "not a take id" }, { status: 400 }); if (url.searchParams.get("log") === "1") { const text = await readFile(/* turbopackIgnore: true */ path.join(project.dir, "takes", take, RENDER_LOG), "utf8").catch(() => null); if (text === null) return new Response(`take ${take} has no render log`, { status: 404, headers: { "content-type": "text/plain; charset=utf-8" } }); return new Response(text, { headers: { "content-type": "text/plain; charset=utf-8", "cache-control": "no-store" } }); } const rec = await takeRender(project.dir, take); if (!rec) return Response.json({ error: `take ${take} has no render record` }, { status: 404 }); return Response.json(rec, { headers: { "cache-control": "no-store" } }); }