import { z } from 'zod' // Generous enough for a photo, small enough to keep rows (and the customer-facing // page that loads them up front) from bloating — these are data: URLs stored // inline, not uploads to disk-backed storage, which this app doesn't have. export const MAX_TABLE_IMAGE_BYTES = 2_000_000 export const ACCEPTED_IMAGE_TYPES = ['image/png', 'image/jpeg', 'image/webp'] export const dataUrlImageSchema = z .string() .trim() .max(Math.ceil((MAX_TABLE_IMAGE_BYTES * 4) / 3) + 100) .regex(/^data:image\/(png|jpeg|jpg|webp);base64,/, 'Bild muss als PNG, JPEG oder WebP hochgeladen werden') .nullable() export function readImageAsDataUrl(file: File): Promise { return new Promise((resolve, reject) => { const reader = new FileReader() reader.onload = () => resolve(reader.result as string) reader.onerror = () => reject(reader.error ?? new Error('Datei konnte nicht gelesen werden')) reader.readAsDataURL(file) }) }