全面清理冗余与过度分层

后端优化:
- 合并 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

@@ -23,6 +23,18 @@ def _to_datetime(value: Union[str, datetime, None]) -> Optional[datetime]:
return None
def _row_to_proxy(row: Tuple) -> Proxy:
return Proxy(
ip=row[0],
port=row[1],
protocol=row[2],
score=row[3],
response_time_ms=row[4],
last_check=_to_datetime(row[5]),
created_at=_to_datetime(row[6]),
)
class ProxyRepository:
"""代理 Repository"""
@@ -125,15 +137,7 @@ class ProxyRepository:
) as cursor:
row = await cursor.fetchone()
if row:
return Proxy(
ip=row[0],
port=row[1],
protocol=row[2],
score=row[3],
response_time_ms=row[4],
last_check=_to_datetime(row[5]),
created_at=_to_datetime(row[6]),
)
return _row_to_proxy(row)
return None
@staticmethod
@@ -143,15 +147,7 @@ class ProxyRepository:
) as cursor:
row = await cursor.fetchone()
if row:
return Proxy(
ip=row[0],
port=row[1],
protocol=row[2],
score=row[3],
response_time_ms=row[4],
last_check=_to_datetime(row[5]),
created_at=_to_datetime(row[6]),
)
return _row_to_proxy(row)
return None
@staticmethod
@@ -170,18 +166,7 @@ class ProxyRepository:
async with db.execute(query, params) as cursor:
rows = await cursor.fetchall()
return [
Proxy(
ip=row[0],
port=row[1],
protocol=row[2],
score=row[3],
response_time_ms=row[4],
last_check=_to_datetime(row[5]),
created_at=_to_datetime(row[6]),
)
for row in rows
]
return [_row_to_proxy(row) for row in rows]
@staticmethod
async def list_paginated(
@@ -223,18 +208,7 @@ class ProxyRepository:
params.extend([page_size, offset])
async with db.execute(data_query, params) as cursor:
rows = await cursor.fetchall()
proxies = [
Proxy(
ip=row[0],
port=row[1],
protocol=row[2],
score=row[3],
response_time_ms=row[4],
last_check=_to_datetime(row[5]),
created_at=_to_datetime(row[6]),
)
for row in rows
]
proxies = [_row_to_proxy(row) for row in rows]
return proxies, total
@staticmethod