import { NextRequest, NextResponse } from "next/server"; import { isExtAuthorized } from "@/lib/render-pipeline/ext-auth"; import { toErrorResponse } from "@/lib/render-pipeline/errors"; import { createBlenderJob, createBlenderJobSchema } from "@/lib/render-pipeline/blender"; // ── POST /api/ext/render/blender ───────────────────────────────────────────── // // Queue a standalone Blender render from the Blender add-on. No Export, no shot // version, no validation or QC — the .blend is already set up to render, and // this puts it on the farm instead of on the artist's machine. export async function POST(req: NextRequest) { if (!isExtAuthorized(req)) { return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); } let raw: unknown; try { raw = await req.json(); } catch { return NextResponse.json({ error: "Invalid JSON" }, { status: 400 }); } const parsed = createBlenderJobSchema.safeParse(raw); if (!parsed.success) { return NextResponse.json({ error: "Invalid Blender job", details: parsed.error.issues }, { status: 422 }); } try { const result = await createBlenderJob(parsed.data); return NextResponse.json(result, { status: 201 }); } catch (err) { const { body, status } = toErrorResponse(err); return NextResponse.json(body, { status }); } }