import { NextRequest, NextResponse } from "next/server"; import { isExtAuthorized } from "@/lib/render-pipeline/ext-auth"; import { toErrorResponse } from "@/lib/render-pipeline/errors"; import { reportProgress } from "@/lib/render-pipeline/jobs"; // ── PATCH /api/ext/render/jobs/{jobId}/progress (E9) ───────────────────────── // // Progress/ETA report; renews the job lease. Response carries cancelRequested // so a worker learns about cancellation without any server→worker connection. export async function PATCH( req: NextRequest, { params }: { params: Promise<{ jobId: string }> } ) { if (!isExtAuthorized(req)) { return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); } const { jobId } = await params; let body: { machineId?: string; progress?: number; currentFrame?: number; totalFrames?: number; etaSeconds?: number; logTail?: 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 reportProgress(jobId, body.machineId, body); return NextResponse.json(result); } catch (err) { const { body: errBody, status } = toErrorResponse(err); return NextResponse.json(errBody, { status }); } }