Files
dticket.tootaio.com/server/api/public/bookings/[token]/transaction-document.get.ts
xiaomai a56a6706b0 feat(bookings): add payment and document upload to confirmation page
Allow users to select payment method and upload receipts before confirming.
Add public API endpoints for payment updates and document management.
2026-05-09 13:15:45 +08:00

30 lines
1.1 KiB
TypeScript

import { sendStream, setHeader } from 'h3'
import { getBookingTransactionDocumentByConfirmationToken } from '../../../../utils/booking-repository'
import { getRequiredRouteParam, httpError } from '../../../../utils/http'
import {
getSafeDownloadName,
getTransactionDocumentFile
} from '../../../../utils/transaction-documents'
export default defineEventHandler(async (event) => {
const token = getRequiredRouteParam(event, 'token', 'Confirmation token')
const document = await getBookingTransactionDocumentByConfirmationToken(token)
if (!document) {
httpError(404, 'Transaction document not found')
}
const file = await getTransactionDocumentFile(document.storageName)
const downloadName = getSafeDownloadName(document.originalName)
setHeader(event, 'content-type', document.mimeType)
setHeader(event, 'content-length', String(file.size))
setHeader(event, 'content-disposition', `attachment; filename="${downloadName}"`)
setHeader(event, 'x-content-type-options', 'nosniff')
setHeader(event, 'cache-control', 'private, no-store')
setHeader(event, 'content-security-policy', 'sandbox')
return sendStream(event, file.stream)
})