from __future__ import annotations import os from pathlib import Path class Config: """Bootstrap configuration. For a basic install, ``THOUGHTSYNC_DATABASE_URL`` is the ONLY required env var — every other tunable lives in the DB-backed Settings UI (rule 25). The only other env var is an optional "break-glass" item: - ``THOUGHTSYNC_SECRET_KEY`` — optional override for the cookie-signing secret. If unset, a key is generated and persisted in the DB (see ``thoughtsync.settings.load_or_create_secret_key``), so sessions survive restarts with no volume required. Uploaded media lives under ``DATA_DIR`` — a fixed, authoritative path (``/var/thoughtsync``), intentionally NOT configurable (a mutable data path only invites breakage). Mount a volume there if you want uploads to persist across container recreation; a text-notes-only install never writes to it. """ DATA_DIR = "/var/thoughtsync" DATABASE_URL = os.environ.get( "THOUGHTSYNC_DATABASE_URL", "postgresql+asyncpg://thoughtsync:thoughtsync@localhost:5432/thoughtsync", ) @classmethod def media_root(cls) -> Path: return Path(cls.DATA_DIR) / "media" @classmethod def client_root(cls) -> Path: """Where the Android APK this server hands out lives. Under DATA_DIR rather than baked into the image: the APK is ~55 MiB and an install that never touches Android should not carry it. Being on the same mounted volume as uploads also means an operator drops a build there once and container recreation does not lose it. See client_dist.py. """ return Path(cls.DATA_DIR) / "client" @classmethod def secret_key_env(cls) -> str | None: """Optional break-glass override for the cookie-signing secret.""" return os.environ.get("THOUGHTSYNC_SECRET_KEY") or None