"""Application settings for PunimTag Web.""" from __future__ import annotations import os from pathlib import Path APP_TITLE = "PunimTag Web API" APP_VERSION = "0.1.0" # Photo storage settings PHOTO_STORAGE_DIR = os.getenv("PHOTO_STORAGE_DIR", "data/uploads") def _project_root() -> Path: """Repository root (parent of ``backend/``).""" return Path(__file__).resolve().parent.parent def get_web_video_cache_directory() -> Path: """Filesystem directory for browser-safe transcoded MP4 cache. Resolution order: 1. ``WEB_VIDEO_CACHE_DIR`` if set (absolute or relative to project root). 2. Otherwise ``/web_videos`` when ``UPLOAD_DIR`` or ``PENDING_PHOTOS_DIR`` is set (same layout as ``.../pending-photos`` next to ``.../web_videos``). 3. Otherwise ``/data/web_videos`` for local dev when no upload dir is configured on the API process. """ explicit = (os.getenv("WEB_VIDEO_CACHE_DIR") or "").strip() if explicit: path = Path(explicit).expanduser() if not path.is_absolute(): path = (_project_root() / path).resolve() else: path = path.resolve() path.mkdir(parents=True, exist_ok=True) return path pending_raw = (os.getenv("UPLOAD_DIR") or os.getenv("PENDING_PHOTOS_DIR") or "").strip() if pending_raw: pending = Path(pending_raw).expanduser() if not pending.is_absolute(): pending = (_project_root() / pending).resolve() else: pending = pending.resolve() out = (pending.parent / "web_videos").resolve() out.mkdir(parents=True, exist_ok=True) return out fallback = (_project_root() / "data" / "web_videos").resolve() fallback.mkdir(parents=True, exist_ok=True) return fallback