import { readFile } from "node:fs/promises"; import { queueDir } from "@/lib/queue/runner"; import { isQid, logFileOf } from "@/lib/queue/store.mjs"; export const dynamic = "force-dynamic"; // GET ?qid=[&attempt=] a queue step's FULL log, as text (what // `umtool queue log ` prints). The path is built from the qid alone. export async function GET(request: Request) { const url = new URL(request.url); const qid = url.searchParams.get("qid"); if (!isQid(qid)) return new Response("?qid=", { status: 400 }); const n = url.searchParams.get("attempt"); const attempt = n && /^[1-9][0-9]{0,3}$/.test(n) ? Number(n) : null; const text = await readFile(/* turbopackIgnore: true */ logFileOf(queueDir(), qid, attempt), "utf8").catch(() => null); if (text === null) return new Response(`no log for ${qid}${attempt ? ` attempt ${attempt}` : ""} (yet)`, { 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" } }); }