config.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from pathlib import Path
  2. from typing import Dict, List
  3. from enum import Enum
  4. import json
  5. class Settings:
  6. BASE_PATH = Path(__file__).parent.parent.parent.absolute()
  7. CONFIG_PATH = BASE_PATH / 'Config.json'
  8. API_PREFIX: str = "/api" # 通用前缀
  9. DATA_DIR = BASE_PATH / "Data"
  10. SCORE_CONFIG_PATH = BASE_PATH / "app/core/scoring_config.json"
  11. # --- 数据库配置 ---
  12. DB_NAME = 'card_score_database'
  13. # 从 Config.json 读取的旧表名, 我们将不再使用它, 但保留以兼容旧文件
  14. # 建议直接在代码中定义新表名, 避免混淆
  15. DB_LEGACY_TABLE_NAME = 'image_records'
  16. DB_CARD_TABLE_NAME = 'cards'
  17. DB_IMAGE_TABLE_NAME = 'card_images' # 新的图片表名
  18. DATABASE_CONFIG: Dict[str, str] = {
  19. 'user': 'root',
  20. 'password': '123456',
  21. 'host': '127.0.0.1',
  22. }
  23. # 连接到指定数据库的配置
  24. DATABASE_CONFIG_WITH_DB: Dict[str, str] = {
  25. **DATABASE_CONFIG,
  26. 'database': DB_NAME
  27. }
  28. def set_config(self):
  29. with open(self.CONFIG_PATH, 'r') as f:
  30. config_json = json.load(f)
  31. self.DATABASE_CONFIG = config_json["mysql_config"]
  32. self.DB_NAME = config_json["database_name"]
  33. settings = Settings()
  34. print(f"项目根目录: {settings.BASE_PATH}")
  35. print(f"数据存储目录: {settings.DATA_DIR}")