import { NextRequest, NextResponse } from "next/server"; import { auth } from "@/auth"; import { db } from "@/lib/db"; import { shotThumbnail } from "@/lib/shot-thumbnail"; // GET /api/storyboard/shots?projectId=xxx export async function GET(req: NextRequest) { const session = await auth(); if (!session?.user) return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); if (!["ADMIN", "PRODUCER", "SUPERVISOR"].includes(session.user.role)) { return NextResponse.json({ error: "Forbidden" }, { status: 403 }); } const projectId = req.nextUrl.searchParams.get("projectId"); if (!projectId) return NextResponse.json({ error: "projectId required" }, { status: 400 }); const shots = await db.shot.findMany({ where: { projectId }, select: { id: true, shotCode: true, scene: true, episode: true, shotNumber: true, sequence: true, description: true, notes: true, status: true, thumbnailUrl: true, generatedThumbnailUrl: true, frameStart: true, frameEnd: true, fps: true, isKeyShot: true, shotVersion: true, shotGroup: { select: { id: true, name: true } }, }, orderBy: [ { episode: "asc" }, { scene: "asc" }, { shotNumber: "asc" }, ], }); // The reference still wins; a render-derived one fills the gap where a show // shipped no stills at all (lib/shot-thumbnail.ts). return NextResponse.json({ shots: shots.map(({ generatedThumbnailUrl, ...shot }) => ({ ...shot, thumbnailUrl: shotThumbnail({ ...shot, generatedThumbnailUrl }), })), }); }