import { cancelDraftJob, errorResponse, readDraftJob } from "@/lib/articles/generation"; export const dynamic = "force-dynamic"; // AN EDITOR JOB'S PROGRESS (release 27 S8): GET ?id=&tail=N reads the // editor's GET /api/ops/job/ (its status, its place in the queue, its // log's last lines); POST { cancel: } is `pnpm ops job cancel`. The // page polls this no faster than every two seconds. export async function GET(request: Request) { const url = new URL(request.url); const id = url.searchParams.get("id") ?? ""; try { return Response.json({ job: await readDraftJob(id, Number(url.searchParams.get("tail") ?? 12) || 12) }, { headers: { "cache-control": "no-store" } }); } catch (err) { return errorResponse(err); } } export async function POST(request: Request) { const body = (await request.json().catch(() => ({}))) as { cancel?: unknown }; try { await cancelDraftJob(String(body.cancel ?? "")); return Response.json({ ok: true }); } catch (err) { return errorResponse(err); } }