Files
ProxyPool/api/deps.py
祀梦 b77641f059 全面清理冗余与过度分层
后端优化:
- 合并 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,避免自动化调用时挂起
2026-04-02 12:26:22 +08:00

51 lines
1.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""依赖注入"""
from fastapi import Request
from services.proxy_service import ProxyService
from services.plugin_service import PluginService
from services.scheduler_service import SchedulerService
from services.validator_service import ValidatorService
from repositories.proxy_repo import ProxyRepository
from core.tasks.queue import ValidationQueue
from core.config import settings as app_settings
def get_proxy_service() -> ProxyService:
return ProxyService()
def get_plugin_service() -> PluginService:
return PluginService()
def get_scheduler_service(request: Request) -> SchedulerService:
return request.app.state.scheduler_service
def get_validation_queue(request: Request) -> ValidationQueue:
return request.app.state.validation_queue
def create_scheduler_service() -> SchedulerService:
"""在应用启动时创建 SchedulerService非请求上下文"""
validator = ValidatorService(
timeout=app_settings.validator_timeout,
connect_timeout=app_settings.validator_connect_timeout,
max_concurrency=app_settings.validator_max_concurrency,
)
proxy_repo = ProxyRepository()
queue = ValidationQueue(
validator=validator,
proxy_repo=proxy_repo,
db_ctx=get_db,
worker_count=app_settings.validator_max_concurrency,
score_valid=app_settings.score_valid,
score_invalid=app_settings.score_invalid,
score_min=app_settings.score_min,
score_max=app_settings.score_max,
)
return SchedulerService(validation_queue=queue, proxy_repo=proxy_repo)
# 避免循环导入
from core.db import get_db