This commit is contained in:
riglen
2026-03-31 15:51:18 +08:00
parent e3cc26d4f6
commit 0d49398e2d
21 changed files with 1483 additions and 0 deletions

41
app/config.py Normal file
View File

@@ -0,0 +1,41 @@
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()