import { NextRequest, NextResponse } from "next/server"; import { isExtAuthorized } from "@/lib/render-pipeline/ext-auth"; import { toErrorResponse } from "@/lib/render-pipeline/errors"; import { deliveryReportSchema, reportDeliveryBuild } from "@/lib/render-pipeline/deliveries"; // ── POST /api/ext/render/jobs/{jobId}/delivery ─────────────────────────────── // // The worker finished (or gave up on) a DELIVERY_BUILD job: per-item results, // the manifest it wrote, and whether the package as a whole is good. 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 = deliveryReportSchema.safeParse(raw); if (!parsed.success) { return NextResponse.json({ error: "Delivery report is malformed", details: parsed.error.issues }, { status: 422 }); } try { const result = await reportDeliveryBuild(jobId, parsed.data); return NextResponse.json(result); } catch (err) { const { body, status } = toErrorResponse(err); return NextResponse.json(body, { status }); } }