主要变更: - 后端代码从根目录迁移到 app/ 目录 - 前端代码从 frontend/ 重命名为 WebUI/ - 更新所有导入路径以适配新结构 - 提取公共 API 响应函数到 app/api/common.py - 精简验证器服务代码 - 更新启动脚本和文档 测试: - 新增完整测试套件 (tests/) - 单元测试: 模型、仓库层 - 集成测试: 覆盖所有 22+ API 端点 - E2E 测试: 4个完整工作流场景 - 添加 pytest 配置和测试运行脚本
60 lines
1.5 KiB
Python
60 lines
1.5 KiB
Python
"""全局配置 - 使用 Pydantic Settings 支持环境变量和 .env 文件"""
|
|
import os
|
|
from typing import List
|
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
model_config = SettingsConfigDict(
|
|
env_file=".env",
|
|
env_file_encoding="utf-8",
|
|
extra="ignore",
|
|
)
|
|
|
|
# 数据库配置
|
|
db_path: str = "db/proxies.sqlite"
|
|
|
|
# API 服务配置
|
|
host: str = "0.0.0.0"
|
|
port: int = 9949
|
|
|
|
# 验证器配置
|
|
validator_timeout: int = 5
|
|
validator_max_concurrency: int = 200
|
|
validator_connect_timeout: int = 3
|
|
|
|
# 爬虫配置
|
|
crawler_num_validators: int = 50
|
|
crawler_max_queue_size: int = 500
|
|
|
|
# 日志配置
|
|
log_level: str = "INFO"
|
|
log_dir: str = "logs"
|
|
|
|
# 导出配置
|
|
export_max_records: int = 10000
|
|
|
|
# 代理评分配置
|
|
score_valid: int = 10
|
|
score_invalid: int = -5
|
|
score_min: int = 0
|
|
score_max: int = 100
|
|
|
|
# 插件配置
|
|
plugins_dir: str = "plugins"
|
|
|
|
# CORS 配置
|
|
cors_origins: str = "http://localhost:8080,http://localhost:5173,http://localhost:9948"
|
|
|
|
@property
|
|
def cors_origins_list(self) -> List[str]:
|
|
return [origin.strip() for origin in self.cors_origins.split(",") if origin.strip()]
|
|
|
|
@property
|
|
def base_dir(self) -> str:
|
|
return os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
|
|
# 全局配置实例(启动时加载一次)
|
|
settings = Settings()
|