import { NextRequest, NextResponse } from "next/server"; import { isExtAuthorized } from "@/lib/render-pipeline/ext-auth"; import { toErrorResponse } from "@/lib/render-pipeline/errors"; import { regeneratePreview } from "@/lib/render-pipeline/preview"; // ── POST /api/ext/exports/{exportId}/regenerate-preview (E15b) ─────────────── // // Rebuild the preview MOV/MP4 for an export that already delivered one, after a // slate or burn-in mistake was caught. Reuses the validated EXRs and keeps the // version number; slate text edited on the web app's Slate tab is picked up. // // Body (all optional): // vfxScope per-export override; omit to re-read the shot's slate field // submissionNote same // note audit note for the ExportEvent export async function POST( req: NextRequest, { params }: { params: Promise<{ exportId: string }> } ) { if (!isExtAuthorized(req)) { return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); } const { exportId } = await params; let body: { vfxScope?: string | null; submissionNote?: string | null; note?: string; } = {}; try { const parsed = await req.json(); if (parsed && typeof parsed === "object") body = parsed; } catch { // empty body is fine — everything falls back to the shot's slate fields } try { const result = await regeneratePreview(exportId, { ...(body.vfxScope !== undefined ? { vfxScope: body.vfxScope } : {}), ...(body.submissionNote !== undefined ? { submissionNote: body.submissionNote } : {}), note: typeof body.note === "string" ? body.note : "Regenerate preview from AE panel", }); return NextResponse.json(result); } catch (err) { const { body: errBody, status } = toErrorResponse(err); return NextResponse.json(errBody, { status }); } }