全面清理冗余与过度分层

后端优化:
- 合并 api/routes/stats.py 到 api/routes/proxies.py,统计接口变更为 /api/proxies/stats
- 内联 services/settings_service.py:settings.py 和 scheduler.py 直接使用 SettingsRepository
- 简化 repositories/proxy_repo.py:提取 _row_to_proxy 辅助函数,消除重复构造代码
- 更新 api/lifespan.py 和 api/deps.py,移除对 settings_service 的依赖
- 从 requirements.txt 移除 websockets 依赖(已废弃的 WebSocket 功能残留)

前端适配:
- 更新 frontend/src/api/index.js:stats 接口路径同步为 /api/proxies/stats
- 清理 api/index.js 中未使用的 createRequestConfig 和多余 JSDoc 注释

脚本优化:
- 移除 script/stop.bat 末尾的 pause,避免自动化调用时挂起
This commit is contained in:
祀梦
2026-04-02 12:26:22 +08:00
parent 33a038367d
commit b77641f059
12 changed files with 68 additions and 194 deletions

View File

@@ -1,9 +1,11 @@
"""代理相关路由"""
"""代理相关路由(含统计信息)"""
from typing import Optional
from fastapi import APIRouter, Depends, Query
from services.proxy_service import ProxyService
from services.scheduler_service import SchedulerService
from models.schemas import ProxyListRequest, BatchDeleteRequest
from api.deps import get_proxy_service
from api.deps import get_proxy_service, get_scheduler_service
from core.log import logger
router = APIRouter(prefix="/api/proxies", tags=["proxies"])
@@ -16,6 +18,20 @@ def error_response(message: str, code: int = 500):
return {"code": code, "message": message, "data": None}
@router.get("/stats")
async def get_stats(
proxy_service: ProxyService = Depends(get_proxy_service),
scheduler_service: SchedulerService = Depends(get_scheduler_service),
):
try:
stats = await proxy_service.get_stats()
stats["scheduler_running"] = scheduler_service.running
return success_response("获取统计信息成功", stats)
except Exception as e:
logger.error(f"Get stats failed: {e}")
return error_response("获取统计信息失败")
@router.post("")
async def list_proxies(
request: ProxyListRequest,