import { NextRequest, NextResponse } from "next/server"; import { ExportStatus } from "@prisma/client"; import { toErrorResponse } from "@/lib/render-pipeline/errors"; import { requirePipelineUser } from "@/lib/render-pipeline/session-auth"; import { listExports } from "@/lib/render-pipeline/exports"; // ── GET /api/render/queue (E21) ────────────────────────────────────────────── // // Exports list for the Render Queue page. Optional filters: projectId, // episode, status; standard pagination. Defaults to all statuses so the queue // page can show history too — the UI filters live states client-side. export async function GET(req: NextRequest) { try { await requirePipelineUser(); const { searchParams } = new URL(req.url); const status = searchParams.get("status") ?? undefined; const result = await listExports({ projectId: searchParams.get("projectId") ?? undefined, episode: searchParams.get("episode") ?? undefined, shotId: searchParams.get("shotId") ?? undefined, status: status && (Object.values(ExportStatus) as string[]).includes(status) ? (status as ExportStatus) : undefined, page: Number(searchParams.get("page") ?? "1") || 1, limit: Number(searchParams.get("limit") ?? "50") || 50, }); return NextResponse.json(result); } catch (err) { const { body, status } = toErrorResponse(err); return NextResponse.json(body, { status }); } }