import { NextRequest, NextResponse } from "next/server"; import { toErrorResponse, PipelineError } from "@/lib/render-pipeline/errors"; import { requirePipelineUser, requirePipelineAdmin } from "@/lib/render-pipeline/session-auth"; import { updateMachine, type MachineAvailability } from "@/lib/render-pipeline/machines"; // ── PATCH /api/machines/{machineId} ────────────────────────────────────────── // // Body (all optional): // enabled: boolean — admin kill-switch (admin/producer/supervisor) // availability: {...}|null — §7.10 schedule config (admin/producer/supervisor) // renderNowHours: number|0 — "Render Now" override (any studio user); // 0 or null clears it export async function PATCH( req: NextRequest, { params }: { params: Promise<{ machineId: string }> } ) { try { const { machineId } = await params; let body: { enabled?: boolean; availability?: MachineAvailability | null; renderNowHours?: number | null }; try { body = await req.json(); } catch { throw new PipelineError(400, "Invalid JSON"); } // Render Now is available to every studio user (§7.10); enable/disable and // availability windows are admin-level controls. if (body.enabled !== undefined || body.availability !== undefined) { await requirePipelineAdmin(); } else { await requirePipelineUser(); } const result = await updateMachine(machineId, body); return NextResponse.json(result); } catch (err) { const { body, status } = toErrorResponse(err); return NextResponse.json(body, { status }); } }