import { NextRequest, NextResponse } from "next/server"; import { isExtAuthorized } from "@/lib/render-pipeline/ext-auth"; import { toErrorResponse } from "@/lib/render-pipeline/errors"; import { reportValidation, validationReportSchema } from "@/lib/render-pipeline/validation"; // ── POST /api/ext/render/jobs/{jobId}/validation (E12) ─────────────────────── // // The worker reports every check from one validation run in a single call. // Any FAIL stops the pipeline (Export → VALIDATION_FAILED); otherwise the // preview stage is queued. export async function POST( req: NextRequest, { params }: { params: Promise<{ jobId: string }> } ) { if (!isExtAuthorized(req)) { return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); } const { jobId } = await params; let raw: unknown; try { raw = await req.json(); } catch { return NextResponse.json({ error: "Invalid JSON" }, { status: 400 }); } const parsed = validationReportSchema.safeParse(raw); if (!parsed.success) { return NextResponse.json( { error: "Validation report is malformed", details: parsed.error.issues }, { status: 422 } ); } try { const result = await reportValidation(jobId, parsed.data); return NextResponse.json(result); } catch (err) { const { body, status } = toErrorResponse(err); return NextResponse.json(body, { status }); } }