config.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. from functools import lru_cache
  2. from pathlib import Path
  3. from dotenv import load_dotenv
  4. from pydantic_settings import BaseSettings, SettingsConfigDict
  5. _BASE_DIR = Path(__file__).resolve().parent.parent
  6. _ENV_FILE = _BASE_DIR / ".env"
  7. load_dotenv(_ENV_FILE)
  8. class Settings(BaseSettings):
  9. model_config = SettingsConfigDict(
  10. env_file=str(_ENV_FILE),
  11. env_file_encoding="utf-8",
  12. env_prefix="TAPPO_",
  13. case_sensitive=False,
  14. )
  15. app_name: str = "TappoCloud Store API"
  16. debug: bool = False
  17. db_host: str = "localhost"
  18. db_port: int = 3306
  19. db_user: str = "root"
  20. db_password: str = ""
  21. db_name: str = "tappocloud"
  22. default_page_size: int = 20
  23. max_page_size: int = 100
  24. # JWT
  25. jwt_secret: str = "change-me-in-production"
  26. jwt_algorithm: str = "HS256"
  27. jwt_expire_hours: int = 24
  28. # Storage
  29. storage_base_url: str = "http://localhost:8000/storage"
  30. storage_path: Path = _BASE_DIR / "storage"
  31. @property
  32. def database_url(self) -> str:
  33. return f"mysql+aiomysql://{self.db_user}:{self.db_password}@{self.db_host}:{self.db_port}/{self.db_name}"
  34. @lru_cache
  35. def get_settings() -> Settings:
  36. return Settings()