import { NextRequest, NextResponse } from "next/server"; import { db } from "@/lib/db"; import { validateReviewToken } from "@/lib/review-auth"; import { generateHetznerDownloadUrl } from "@/lib/storage"; /** * GET /api/client/[token]/shots/[shotId]/highres/download * Validates the client review token then returns a presigned Hetzner download URL. */ export async function GET( req: NextRequest, { params }: { params: Promise<{ token: string; shotId: string }> } ) { const { token, shotId } = await params; const result = await validateReviewToken(token, req); if (result.type !== "ok") { return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); } const shot = await db.shot.findUnique({ where: { id: shotId }, select: { highResKey: true, highResFilename: true, projectId: true }, }); // Ensure the shot belongs to the review session's project if (!shot || shot.projectId !== result.session.projectId) { return NextResponse.json({ error: "Not found" }, { status: 404 }); } if (!shot.highResKey || !shot.highResFilename) { return NextResponse.json({ error: "No high-res file available" }, { status: 404 }); } const url = await generateHetznerDownloadUrl(shot.highResKey, shot.highResFilename); return NextResponse.json({ url }); }