from __future__ import annotations from functools import lru_cache from pathlib import Path from pydantic import Field from pydantic_settings import BaseSettings, SettingsConfigDict ROOT_DIR = Path(__file__).resolve().parent.parent CONFIG_DIR = ROOT_DIR / "config" DATA_DIR = ROOT_DIR / "data" class Settings(BaseSettings): app_name: str = "sub-provider" app_env: str = "prod" host: str = "0.0.0.0" port: int = 18080 log_level: str = "info" public_path: str = Field(default="change-me-random-hash-path") public_base_url: str | None = None request_timeout_seconds: float = 20.0 cache_ttl_seconds: int = 900 max_proxy_name_length: int = 80 default_user_agent: str = "sub-provider/0.2" sources_file: Path = CONFIG_DIR / "sources.yaml" rules_dir: Path = CONFIG_DIR / "rules" model_config = SettingsConfigDict( env_file=ROOT_DIR / ".env", env_file_encoding="utf-8", extra="ignore", ) @lru_cache(maxsize=1) def get_settings() -> Settings: return Settings()