This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import { NextResponse } from "next/server"
|
||||
|
||||
import { getInvitationByToken } from "@/lib/db/queries/invitations"
|
||||
import { isRsvpClosed } from "@/lib/rsvp-deadline"
|
||||
import {
|
||||
createInvitationUploadKey,
|
||||
createPresignedUploadUrl,
|
||||
} from "@/lib/storage/uploads"
|
||||
import { presignUploadSchema } from "@/lib/validation/upload"
|
||||
|
||||
export const runtime = "nodejs"
|
||||
|
||||
export async function POST(request: Request) {
|
||||
if (isRsvpClosed()) {
|
||||
return NextResponse.json({ message: "Upload deadline has passed" }, { status: 403 })
|
||||
}
|
||||
|
||||
const parsed = presignUploadSchema.safeParse(await request.json())
|
||||
|
||||
if (!parsed.success) {
|
||||
return NextResponse.json({ message: "Invalid upload request" }, { status: 400 })
|
||||
}
|
||||
|
||||
const invitation = await getInvitationByToken(parsed.data.token)
|
||||
|
||||
if (!invitation) {
|
||||
return NextResponse.json({ message: "Invitation not found" }, { status: 404 })
|
||||
}
|
||||
|
||||
const objectKey = createInvitationUploadKey(
|
||||
invitation.invitation.id,
|
||||
parsed.data.filename,
|
||||
)
|
||||
const uploadUrl = await createPresignedUploadUrl({
|
||||
objectKey,
|
||||
contentType: parsed.data.contentType,
|
||||
sizeBytes: parsed.data.sizeBytes,
|
||||
})
|
||||
|
||||
return NextResponse.json({ objectKey, uploadUrl })
|
||||
}
|
||||
Reference in New Issue
Block a user