47 lines
1.5 KiB
Python
47 lines
1.5 KiB
Python
"""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/"
|
|
|
|
|
|
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()
|
|
|
|
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", "gpt-4o-mini"),
|
|
"ALT_TEXT_DB": os.getenv("ALT_TEXT_DB", ""),
|
|
"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
|