AnlaAnla 3 mesiacov pred
rodič
commit
9d21e2d4fc
5 zmenil súbory, kde vykonal 33 pridanie a 1 odobranie
  1. 2 0
      .gitignore
  2. 6 0
      .idea/vcs.xml
  3. 9 0
      Config.json
  4. 14 1
      app/core/config.py
  5. 2 0
      app/main.py

+ 2 - 0
.gitignore

@@ -0,0 +1,2 @@
+/Data/
+/app.log

+ 6 - 0
.idea/vcs.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
+  </component>
+</project>

+ 9 - 0
Config.json

@@ -0,0 +1,9 @@
+{
+  "mysql_config": {
+    "user": "root",
+    "password": "123456",
+    "host": "127.0.0.1"
+  },
+  "database_name": "card_score_database",
+  "database_table_name": "image_records"
+}

+ 14 - 1
app/core/config.py

@@ -1,12 +1,17 @@
 from pathlib import Path
 from typing import Dict, List
 from enum import Enum
+import json
 
 
 class Settings:
-    API_ImageData_prefix: str = "/api/image_data"
+
     BASE_PATH = Path(__file__).parent.parent.parent.absolute()
 
+    CONFIG_PATH = BASE_PATH / 'Config.json'
+
+    API_ImageData_prefix: str = "/api/image_data"
+
     DATA_DIR = BASE_PATH / "Data"
     SCORE_CONFIG_PATH = BASE_PATH / "app/core/scoring_config.json"
 
@@ -24,6 +29,14 @@ class Settings:
         'database': DB_NAME
     }
 
+    def set_config(self):
+        with open(self.CONFIG_PATH, 'r') as f:
+            config_json = json.load(f)
+
+        self.DATABASE_CONFIG = config_json["mysql_config"]
+        self.DB_NAME = config_json["database_name"]
+        self.DB_TABLE_NAME = config_json["database_table_name"]
+
 
 settings = Settings()
 print(f"项目根目录: {settings.BASE_PATH}")

+ 2 - 0
app/main.py

@@ -15,6 +15,8 @@ logger = get_logger(__name__)
 @asynccontextmanager
 async def lifespan(main_app: FastAPI):
     print("--- 应用启动 ---")
+    settings.set_config()
+
     # --- 文件和目录准备 ---
     os.makedirs(settings.DATA_DIR, exist_ok=True)