import { NextRequest, NextResponse } from "next/server"; import { isExtAuthorized } from "@/lib/render-pipeline/ext-auth"; import { toErrorResponse } from "@/lib/render-pipeline/errors"; import { finalizePreview, type FinalizeInput } from "@/lib/render-pipeline/preview"; // ── POST /api/ext/render/jobs/{jobId}/finalize (E13) ───────────────────────── // // Preview artifacts uploaded → register the review MP4 as an internal-only // Version and move the Export to READY_FOR_QC. Never shares to the client // portal and never changes task/shot status (§10.0). 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 body: FinalizeInput & { machineId?: string }; try { body = await req.json(); } catch { return NextResponse.json({ error: "Invalid JSON" }, { status: 400 }); } if (!body.machineId) { return NextResponse.json({ error: "machineId is required" }, { status: 400 }); } try { const result = await finalizePreview(jobId, body.machineId, body); return NextResponse.json(result); } catch (err) { const { body: errBody, status } = toErrorResponse(err); return NextResponse.json(errBody, { status }); } }