import { NextResponse } from "next/server" import { getInvitationByToken } from "@/lib/db/queries/invitations" import { getPhotoUploadByInvitationId } from "@/lib/db/queries/uploads" import { createPresignedDownloadUrl } from "@/lib/storage/uploads" export const runtime = "nodejs" export async function GET(request: Request) { const token = new URL(request.url).searchParams.get("token") if (!token) return NextResponse.json({ message: "Invitation token is required" }, { status: 400 }) const invitation = await getInvitationByToken(token) if (!invitation) return NextResponse.json({ message: "Invitation not found" }, { status: 404 }) const upload = await getPhotoUploadByInvitationId(invitation.invitation.id) if (!upload) return NextResponse.json({ photo: null }, { headers: { "cache-control": "private, no-store" } }) return NextResponse.json( { photo: { filename: upload.original_filename, url: await createPresignedDownloadUrl(upload.object_key) } }, { headers: { "cache-control": "private, no-store" } }, ) }