26 lines
930 B
TypeScript
26 lines
930 B
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { getLatestExportForShot } from "@/lib/render-pipeline/exports";
|
|
|
|
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;
|
|
return (req.headers.get("x-api-key") ?? "") === apiKey;
|
|
}
|
|
|
|
export async function GET(req: NextRequest) {
|
|
if (!isAuthorized(req)) {
|
|
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
|
}
|
|
|
|
const { searchParams } = new URL(req.url);
|
|
const shotId = searchParams.get("shotId");
|
|
if (!shotId) {
|
|
return NextResponse.json({ error: "shotId query param is required" }, { status: 400 });
|
|
}
|
|
|
|
const exportRecord = await getLatestExportForShot(shotId);
|
|
return NextResponse.json({ export: exportRecord });
|
|
}
|