import os from pathlib import Path from dotenv import load_dotenv load_dotenv() DATA_DIR = os.environ.get("DATA_DIR", "/data") PORT = int(os.environ.get("PORT", "8000")) _SINGLE_USER_VALUES = frozenset({"single_user", "single-user", "singleuser", "single"}) def parse_cookie_mode(raw: str) -> tuple[bool, bool]: """Read `COOKIE_SECURE` as a three-way mode → `(cookie_secure, single_user)`. - `true` (default): cookie-scoped Owners, `Secure` + persistent cookie. - `false`: cookie-scoped Owners over plain HTTP, memory-only cookie — browsers drop `Secure` cookies on HTTP, so the flag has to come off. - `single_user`: no cookie at all. Every request shares one Owner, so a test box or a local single-person deployment needs no session plumbing. Anyone who can reach the app gets that data — there is no separation left to enforce, which is the point. """ value = raw.strip().lower() if value in _SINGLE_USER_VALUES: return False, True return value != "false", False COOKIE_SECURE, SINGLE_USER = parse_cookie_mode(os.environ.get("COOKIE_SECURE", "true")) # Outbound lookups (image search, driver-page search, image download). The only # feature that leaves the box — set false for an air-gapped deployment and the # UI hides every search control instead of timing out on each one. WEB_SEARCH = os.environ.get("WEB_SEARCH", "true").strip().lower() != "false" DB_PATH = str(Path(DATA_DIR) / "imptune.db") DRIVERS_DIR = str(Path(DATA_DIR) / "drivers") ICONS_DIR = str(Path(DATA_DIR) / "icons")