30 lines
958 B
TypeScript
30 lines
958 B
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { auth } from "@/auth";
|
|
import { db } from "@/lib/db";
|
|
import { generateHetznerDownloadUrl } from "@/lib/storage";
|
|
|
|
/** GET /api/shots/[shotId]/highres/download — returns a short-lived presigned download URL */
|
|
export async function GET(
|
|
req: NextRequest,
|
|
{ params }: { params: Promise<{ shotId: string }> }
|
|
) {
|
|
const session = await auth();
|
|
if (!session?.user) {
|
|
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
|
}
|
|
|
|
const { shotId } = await params;
|
|
|
|
const shot = await db.shot.findUnique({
|
|
where: { id: shotId },
|
|
select: { highResKey: true, highResFilename: true },
|
|
});
|
|
|
|
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 });
|
|
}
|