import { articleQuoteChecks, articleReportCheck } from "@/lib/articles/checks"; import { isReportHost } from "@/lib/articles/sites"; export const dynamic = "force-dynamic"; // POST { site, report, what: "quotes" | "check", allowMissingMedia? } // quotes -> every video, audio and post quote against its record (the CLI's // `reports verify-quotes --article`): status, score, track, the // en-orig score, and what plays it // check -> compose's own findings with nothing written (`reports check // --article`, a site's `--reports `): pass, or every problem // lib/articles/checks.ts; read-only, no model. export async function POST(request: Request) { const b = (await request.json().catch(() => null)) as Record | null; const site = String(b?.site ?? ""); const report = String(b?.report ?? ""); if (!isReportHost(site)) return Response.json({ error: `no site ${site}` }, { status: 404 }); if (!/^[a-z0-9][a-z0-9-]{0,63}$/.test(report)) return Response.json({ error: "report must be a report id" }, { status: 400 }); try { const body = b?.what === "check" ? await articleReportCheck(site, report, { allowMissingMedia: b?.allowMissingMedia === true }) : b?.what === "quotes" ? await articleQuoteChecks(site, report) : null; if (!body) return Response.json({ error: "what must be quotes or check" }, { status: 400 }); return Response.json(body, { headers: { "cache-control": "no-store" } }); } catch (e) { return Response.json({ error: e instanceof Error ? e.message : String(e) }, { status: (e as { status?: number })?.status ?? 500 }); } }