config.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. """
  2. 应用配置管理
  3. """
  4. from pydantic_settings import BaseSettings
  5. from pydantic import validator
  6. from typing import List
  7. import os
  8. class Settings(BaseSettings):
  9. """应用配置"""
  10. # 基础配置
  11. APP_NAME: str = "AI角色对话App"
  12. APP_VERSION: str = "1.0.0"
  13. DEBUG: bool = True
  14. # 数据库配置
  15. DATABASE_URL: str
  16. DATABASE_URL_SYNC: str
  17. # Redis配置
  18. REDIS_URL: str
  19. # JWT配置
  20. JWT_SECRET_KEY: str
  21. JWT_ALGORITHM: str = "HS256"
  22. ACCESS_TOKEN_EXPIRE_MINUTES: int = 60
  23. REFRESH_TOKEN_EXPIRE_DAYS: int = 30
  24. # 加密配置
  25. ENCRYPTION_KEY: str
  26. # Celery配置
  27. CELERY_BROKER_URL: str
  28. CELERY_RESULT_BACKEND: str
  29. # CORS配置
  30. CORS_ORIGINS: List[str] = []
  31. # Firebase配置
  32. FIREBASE_CREDENTIALS_PATH: str = ""
  33. # 日志配置
  34. LOG_LEVEL: str = "INFO"
  35. @validator("CORS_ORIGINS", pre=True)
  36. def parse_cors_origins(cls, v):
  37. """解析CORS origins"""
  38. if isinstance(v, str):
  39. return [origin.strip() for origin in v.split(",")]
  40. return v
  41. class Config:
  42. env_file = ".env"
  43. case_sensitive = True
  44. # 创建全局配置实例
  45. settings = Settings()