"""Application configuration helpers.""" from __future__ import annotations import os from typing import Dict from dotenv import load_dotenv DEFAULT_IMMICH_URL = "https://photos.4angle.com/" DEFAULT_OPENAI_MODEL = "gpt-4o-mini" class ConfigError(RuntimeError): """Raised when critical configuration is missing.""" def load_settings() -> Dict[str, str]: """Load configuration from environment variables and ``api_keys``.""" load_dotenv() db_path = os.getenv("STATION_DB", "") settings: Dict[str, str] = { "IMMICH_API_URL": os.getenv("IMMICH_API_URL", DEFAULT_IMMICH_URL).rstrip("/"), "IMMICH_API_KEY": os.getenv("IMMICH_API_KEY", ""), "OPENAI_API_KEY": os.getenv("OPENAI_API_KEY", ""), "RECENT_DAYS": int(os.getenv("RECENT_DAYS", "3")), "OPENAI_MODEL": os.getenv("OPENAI_MODEL", DEFAULT_OPENAI_MODEL), "STATION_DB": db_path, "SECRET_KEY": os.getenv("SECRET_KEY", ""), "MASTODON_BASE_URL": os.getenv( "MASTODON_BASE_URL", "http://localhost:3000" ).rstrip("/"), "MASTODON_ACCESS_TOKEN": os.getenv("MASTODON_ACCESS_TOKEN", ""), "MASTODON_CLIENT_KEY": os.getenv("MASTODON_CLIENT_KEY", ""), "MASTODON_CLIENT_SECRET": os.getenv("MASTODON_CLIENT_SECRET", ""), } missing = [ key for key in ("IMMICH_API_KEY", "OPENAI_API_KEY") if not settings.get(key) ] if missing: raise ConfigError( "Missing required configuration values: " + ", ".join(missing) ) return settings