Changes: - Updated BillingLocation interface: - Added utilBillsProofOfPaymentAttachment field (BillAttachment type) - Added server action uploadUtilBillsProofOfPayment: - Validates PDF file type - Serializes file attachment to base64 - Stores attachment in BillingLocation document - Returns success/error status - Updated ViewLocationCard component: - Added file upload input with PDF-only accept - Implemented handleFileChange with immediate upload - Added upload state management (isUploading, uploadError, attachment) - Shows spinner while uploading - Input disabled during upload - Conditionally renders file input or download link - Link displayed after successful upload - Created route handler for serving proof of payment PDFs: - GET /share/proof-of-payment/[id]/route.tsx - Fetches attachment from database - Converts base64 to binary - Returns PDF with proper headers - Added not-found page for proof of payment route - Updated middleware to include proof-of-payment in public pages - Added translations: - en: "Upload proof of payment (PDF only)" - hr: "Priložite potvrdu o uplati:" File uploads immediately on selection without page reload. Only PDF files accepted with client and server-side validation. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
31 lines
1.2 KiB
TypeScript
31 lines
1.2 KiB
TypeScript
import { getDbClient } from '@/app/lib/dbClient';
|
|
import { BillingLocation } from '@/app/lib/db-types';
|
|
import { notFound } from 'next/navigation';
|
|
|
|
export async function GET(request: Request, { params:{ id } }: { params: { id:string } }) {
|
|
const locationID = id;
|
|
|
|
const dbClient = await getDbClient();
|
|
const location = await dbClient.collection<BillingLocation>("lokacije")
|
|
.findOne({ _id: locationID });
|
|
|
|
if(!location?.utilBillsProofOfPaymentAttachment) {
|
|
notFound();
|
|
}
|
|
|
|
// Convert fileContentsBase64 from Base64 string to binary
|
|
const fileContentsBuffer = Buffer.from(location.utilBillsProofOfPaymentAttachment.fileContentsBase64, 'base64');
|
|
|
|
// Convert fileContentsBuffer to format that can be sent to the client
|
|
const fileContents = new Uint8Array(fileContentsBuffer);
|
|
|
|
return new Response(fileContents, {
|
|
status: 200,
|
|
headers: {
|
|
'Content-Type': 'application/pdf',
|
|
'Content-Disposition': `attachment; filename="${location.utilBillsProofOfPaymentAttachment.fileName}"`,
|
|
'Last-Modified': `${location.utilBillsProofOfPaymentAttachment.fileLastModified}`
|
|
}
|
|
});
|
|
}
|