import io import pathlib import uuid from PIL import Image, UnidentifiedImageError # backend/app/storage.py -> backend/ -> repo root -- same # resolve-relative-to-file convention FRONTEND_DIST uses in app/main.py, so # this lands in the right place in both local dev and the /srv/ds-chat # production layout with zero new config. UPLOADS_DIR = pathlib.Path(__file__).resolve().parent.parent.parent / "uploads" # Seed value for the admin-configurable UploadSettings row (see # app/services/upload_settings_service.py) -- also the fallback `read_capped` # default for call sites that don't look up the live setting. DEFAULT_MAX_UPLOAD_BYTES = 8 * 1024 * 1024 _READ_CHUNK_BYTES = 1024 * 1024 _MAX_DIMENSION = 2000 # (storage extension, Pillow format name) ALLOWED_IMAGE_CONTENT_TYPES: dict[str, tuple[str, str]] = { "image/jpeg": (".jpg", "JPEG"), "image/png": (".png", "PNG"), "image/gif": (".gif", "GIF"), "image/webp": (".webp", "WEBP"), } # #65: browser-natively-playable video formats -- used to decide whether a # stored MessageFile gets served inline (a