From 4ef793194150d4b0ea9725aa2bf501fec8011771 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A5=80=E6=A2=A6?= <3501646051@qq.com> Date: Sat, 4 Apr 2026 21:03:43 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=85=A8=E9=9D=A2=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E9=97=AE=E9=A2=98=E5=B9=B6=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E6=9E=B6=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复问题: - 添加缺失的 httpx 依赖到 requirements.txt - 修复前端批量删除参数格式与后端不匹配(数组->对象数组) - 移除 app/api/main.py 中重复创建 app 的冗余代码 - 修复 Plugins.vue v-model 直接修改 store 状态的 Vue 警告 - 修复 README 端口/启动命令文档与实际配置不一致 - 修正 pytest.ini 过时配置 (asyncio_default_fixture_loop_scope) - 修复 WebUI index.html 语言设置为 zh-CN - 修复 .gitignore 错误忽略 tests/ 目录 后端优化: - 修复调度器默认间隔从 5 秒改为 30 分钟,避免无节制验证 - 修复 validate_all_now 在调度器停止时无法执行的 bug - 设置保存后热更新运行中调度器的验证间隔 - 将 update_score 优化为原子单事务 SQL,消除并发竞态 - 导出功能改为真正的流式分批读取(iter_batches),降低大导出内存占用 - ProxyResponse Schema 补齐 response_time_ms 字段 - 日志级别改为从配置动态读取,不再硬编码 INFO - 清理 validator_service 中的冗余 try/finally 代码 插件健壮性: - 修复 ip3366/ip89/kuaidaili/proxylist_download/speedx/yundaili/proxyscrape 的端口范围检查和 IPv6 地址解析问题(改用 rsplit + 1-65535 校验) - 修复 PluginService.list_plugins 并发竞争条件 - 修复 run_all_plugins 去重逻辑与数据库 UNIQUE 约束保持一致 - 修复 proxyscrape 异常时错误跳过 fallback 的 bug 测试: - 新增 7 个插件解析单元测试 - 新增 update_score 自动删除和 iter_batches 流式读取测试 - 全部 74 个测试通过 --- .gitignore | 2 +- README.md | 14 ++++---- WebUI/index.html | 2 +- WebUI/src/api/index.js | 4 +-- WebUI/src/stores/proxy.js | 2 +- WebUI/src/views/Plugins.vue | 2 +- WebUI/src/views/ProxyList.vue | 2 +- app/api/deps.py | 2 +- app/api/main.py | 3 -- app/api/routes/settings.py | 14 ++++++-- app/core/log.py | 11 ++++++- app/models/schemas.py | 1 + app/plugins/ip3366.py | 7 ++-- app/plugins/ip89.py | 7 ++-- app/plugins/kuaidaili.py | 7 ++-- app/plugins/proxylist_download.py | 12 ++++--- app/plugins/proxyscrape.py | 14 ++++---- app/plugins/speedx.py | 18 ++++++----- app/plugins/yundaili.py | 13 ++++---- app/repositories/proxy_repo.py | 54 ++++++++++++++++++++----------- app/services/plugin_service.py | 11 +++---- app/services/proxy_service.py | 51 ++++++++++++++++++----------- app/services/scheduler_service.py | 20 +++++++++--- app/services/validator_service.py | 18 ++++------- pytest.ini | 2 +- requirements.txt | 1 + tests/unit/test_repositories.py | 31 ++++++++++++++++++ 27 files changed, 212 insertions(+), 113 deletions(-) diff --git a/.gitignore b/.gitignore index c45a9ea..97a145a 100644 --- a/.gitignore +++ b/.gitignore @@ -53,7 +53,7 @@ logs/ # Test test/ -tests/ +# tests/ # 保留测试目录以便版本控制 # Share Directory share/ diff --git a/README.md b/README.md index f69e1e3..d10eb14 100644 --- a/README.md +++ b/README.md @@ -14,12 +14,12 @@ ## 📦 技术栈 ### 后端 -- **框架**: FastAPI (端口 9949) +- **框架**: FastAPI (端口 18080) - **数据库**: SQLite + aiosqlite - **异步**: asyncio ### 前端 -- **框架**: Vue 3 + Vite (端口 9948) +- **框架**: Vue 3 + Vite (端口 18081) - **UI库**: Element Plus - **状态管理**: Pinia - **图表**: ECharts @@ -53,7 +53,7 @@ start.bat **启动后端服务**(终端 1) ```bash -python api_server.py +python main.py ``` **启动前端服务**(终端 2) @@ -71,7 +71,7 @@ stop.bat ### 4. 访问 WebUI -打开浏览器访问:**http://localhost:9948** +打开浏览器访问:**http://localhost:18081** ## 📁 项目结构 @@ -202,10 +202,10 @@ POST /api/settings 2. **手动测试 API** ```bash # 获取统计信息 - curl http://localhost:9949/api/stats + curl http://localhost:18080/api/stats # 获取代理列表 - curl -X POST http://localhost:9949/api/proxies \ + curl -X POST http://localhost:18080/api/proxies \ -H "Content-Type: application/json" \ -d '{"page": 1, "page_size": 20}' ``` @@ -229,7 +229,7 @@ POST /api/settings ## 🔧 常见问题 ### Q: 启动后端口被占用? -A: 修改 `config.py` 中的端口号(默认9949)或 `frontend/vite.config.js` 中的端口号(默认9948) +A: 修改 `.env` 中的端口号(默认18080)或 `WebUI/vite.config.js` 中的端口号(默认18081) ### Q: 爬虫无法抓取代理? A: 检查网络连接,确保能访问目标网站,或尝试更换代理源插件 diff --git a/WebUI/index.html b/WebUI/index.html index 8769dc1..2410242 100644 --- a/WebUI/index.html +++ b/WebUI/index.html @@ -1,5 +1,5 @@ - + diff --git a/WebUI/src/api/index.js b/WebUI/src/api/index.js index d9b781b..3568518 100644 --- a/WebUI/src/api/index.js +++ b/WebUI/src/api/index.js @@ -61,8 +61,8 @@ export const statsAPI = { } export const proxiesAPI = { - getProxies: (params, signal) => - api.post('/api/proxies', cleanParams(params), signal ? { signal } : {}), + getProxies: (params, signal) => + api.post('/api/proxies', cleanParams(params), { signal }), deleteProxy: (ip, port) => api.delete(`/api/proxies/${ip}/${port}`), diff --git a/WebUI/src/stores/proxy.js b/WebUI/src/stores/proxy.js index 970863b..476b67a 100644 --- a/WebUI/src/stores/proxy.js +++ b/WebUI/src/stores/proxy.js @@ -89,7 +89,7 @@ export const useProxyStore = defineStore('proxy', () => { /** * 批量删除代理 - * @param {Array<[string, number|string]>} proxyList + * @param {Array<{ip: string, port: number}>} proxyList * @returns {Promise} 实际删除的数量 */ async function batchDeleteProxies(proxyList) { diff --git a/WebUI/src/views/Plugins.vue b/WebUI/src/views/Plugins.vue index 8874b83..73c039f 100644 --- a/WebUI/src/views/Plugins.vue +++ b/WebUI/src/views/Plugins.vue @@ -46,7 +46,7 @@