api update
Deploy / deploy (push) Successful in 2m33s

This commit is contained in:
twotalesanimation
2026-05-30 10:19:35 +02:00
parent 36ee62dacc
commit 15046892d1
2 changed files with 138 additions and 5 deletions
+97
View File
@@ -0,0 +1,97 @@
import { NextRequest, NextResponse } from "next/server";
import { db } from "@/lib/db";
function isAuthorized(req: NextRequest): boolean {
const apiKey = process.env.API_SECRET_KEY;
if (!apiKey) return false;
const authHeader = req.headers.get("authorization") ?? "";
if (authHeader.startsWith("Bearer ")) {
return authHeader.slice(7) === apiKey;
}
const headerKey = req.headers.get("x-api-key") ?? "";
return headerKey === apiKey;
}
// ── GET /api/ext/shots/[shotId] ───────────────────────────────────────────────
//
// Returns full shot detail including tasks and latest version status.
// Accepts either the database id or the shotCode via query param:
// /api/ext/shots/<id>
// /api/ext/shots/<shotCode>?byCode=1&projectId=<projectId>
export async function GET(
req: NextRequest,
{ params }: { params: Promise<{ shotId: string }> }
) {
if (!isAuthorized(req)) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
const { shotId } = await params;
const { searchParams } = new URL(req.url);
const byCode = searchParams.get("byCode") === "1";
const projectId = searchParams.get("projectId") ?? undefined;
const shot = await db.shot.findFirst({
where: byCode
? { shotCode: shotId, ...(projectId ? { projectId } : {}) }
: { id: shotId },
select: {
id: true,
shotCode: true,
scene: true,
episode: true,
shotNumber: true,
description: true,
status: true,
priority: true,
frameStart: true,
frameEnd: true,
fps: true,
dueDate: true,
createdAt: true,
updatedAt: true,
project: {
select: { id: true, name: true, code: true, showId: true },
},
artist: {
select: { id: true, name: true, email: true },
},
tasks: {
orderBy: { sortOrder: "asc" },
select: {
id: true,
title: true,
type: true,
status: true,
priority: true,
estimatedHours: true,
dueDate: true,
assignedArtist: { select: { id: true, name: true, email: true } },
_count: { select: { versions: true } },
},
},
versions: {
orderBy: { versionNumber: "desc" },
take: 1,
select: {
id: true,
versionNumber: true,
approvalStatus: true,
createdAt: true,
artist: { select: { id: true, name: true, email: true } },
},
},
_count: {
select: { versions: true, tasks: true },
},
},
});
if (!shot) {
return NextResponse.json({ error: "Shot not found" }, { status: 404 });
}
return NextResponse.json({ shot });
}