This commit is contained in:
2026-07-30 10:30:50 +08:00
parent cf6d708566
commit 853c478657
85 changed files with 4711 additions and 1052 deletions
+15 -1
View File
@@ -1,6 +1,6 @@
import os
import urllib.parse
from typing import Dict, Any
from typing import Dict, Any, List
from dotenv import load_dotenv
load_dotenv()
@@ -75,6 +75,11 @@ class Settings:
self.REDIS_PASSWORD = os.getenv("REDIS_PASSWORD", "")
self.REDIS_DB = int(os.getenv("REDIS_DB", "0"))
# CORS 白名单(逗号分隔,默认允许本机开发地址)
self.CORS_ORIGINS = self._parse_cors_origins(
os.getenv("CORS_ORIGINS", "")
)
# LLM 增强分析配置(可选)
self.LLM_ENABLED = os.getenv("LLM_ENABLED", "false").lower() == "true"
self.LLM_API_URL = os.getenv("LLM_API_URL", "https://api.openai.com/v1")
@@ -95,5 +100,14 @@ class Settings:
def allowed_extensions_set(self) -> set:
return set(ext.strip() for ext in self.ALLOWED_EXTENSIONS.split(","))
@staticmethod
def _parse_cors_origins(raw: str) -> List[str]:
"""解析 CORS_ORIGINS 环境变量,逗号分隔。
为空时返回空列表(由 app_factory 决定是否降级为 ['*'])。
"""
if not raw or not raw.strip():
return []
return [o.strip().rstrip("/") for o in raw.split(",") if o.strip()]
settings = Settings()