// Shared upload constraints โ€” imported by both the client ImageDrop // component and the server /api/orders route so the limits can't drift // apart. Plain constants (no 'server-only'), safe in the browser bundle. /** Max accepted upload size: 10 MB. */ export const MAX_UPLOAD_BYTES = 10 * 1024 * 1024; export const MAX_UPLOAD_LABEL = '10MB'; /** Only real JPEG / PNG. HEIC, WebP, GIF, etc. are rejected โ€” the print * pipeline (CF Images โ†’ Prodigi) wants predictable raster formats and * HEIC in particular doesn't render in many browsers. */ export const ACCEPTED_IMAGE_MIME = ['image/jpeg', 'image/png'] as const; /** For the file input's `accept` attribute. */ export const ACCEPTED_IMAGE_ACCEPT = ACCEPTED_IMAGE_MIME.join(','); /** Customer-facing description of what's allowed. */ export const ACCEPTED_IMAGE_LABEL = 'JPG or PNG ยท up to 10MB'; /** Validate a file against type + size. Returns an error message string * if invalid, or null if the file is acceptable. Works with both * browser File objects and the server's FormData File. */ export function validateUpload(file: { type: string; size: number }): string | null { if (!(ACCEPTED_IMAGE_MIME as readonly string[]).includes(file.type)) { return 'Please upload a JPG or PNG image.'; } if (file.size > MAX_UPLOAD_BYTES) { return `That image is over ${MAX_UPLOAD_LABEL}. Please upload a smaller file.`; } return null; }