@@ -0,0 +1,25 @@
|
||||
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 });
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { z } from "zod";
|
||||
import { createRenderExport, listExportsForQueue } 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;
|
||||
}
|
||||
|
||||
const createExportSchema = z.object({
|
||||
shotId: z.string().min(1),
|
||||
projectId: z.string().min(1),
|
||||
manifest: z.unknown(),
|
||||
submittedById: z.string().optional().nullable(),
|
||||
submittedByName: z.string().optional().nullable(),
|
||||
taskId: z.string().optional().nullable(),
|
||||
});
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
if (!isAuthorized(req)) {
|
||||
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
||||
}
|
||||
|
||||
const exports = await listExportsForQueue();
|
||||
return NextResponse.json({ exports });
|
||||
}
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
if (!isAuthorized(req)) {
|
||||
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
||||
}
|
||||
|
||||
try {
|
||||
const body = await req.json();
|
||||
const parsed = createExportSchema.parse(body);
|
||||
const result = await createRenderExport(parsed);
|
||||
return NextResponse.json(result, { status: 201 });
|
||||
} catch (error) {
|
||||
if (error instanceof z.ZodError) {
|
||||
return NextResponse.json({ error: "Validation error", details: error.errors }, { status: 422 });
|
||||
}
|
||||
|
||||
return NextResponse.json({ error: error instanceof Error ? error.message : "Failed to queue export" }, { status: 400 });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { auth } from "@/auth";
|
||||
import { listExportsForQueue } from "@/lib/render-pipeline/exports";
|
||||
|
||||
export async function GET() {
|
||||
const session = await auth();
|
||||
if (!session?.user) {
|
||||
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
||||
}
|
||||
|
||||
const exports = await listExportsForQueue();
|
||||
return NextResponse.json({ exports });
|
||||
}
|
||||
Reference in New Issue
Block a user