主要变更: - 后端代码从根目录迁移到 app/ 目录 - 前端代码从 frontend/ 重命名为 WebUI/ - 更新所有导入路径以适配新结构 - 提取公共 API 响应函数到 app/api/common.py - 精简验证器服务代码 - 更新启动脚本和文档 测试: - 新增完整测试套件 (tests/) - 单元测试: 模型、仓库层 - 集成测试: 覆盖所有 22+ API 端点 - E2E 测试: 4个完整工作流场景 - 添加 pytest 配置和测试运行脚本
52 lines
1.8 KiB
Python
52 lines
1.8 KiB
Python
import re
|
|
from typing import List
|
|
from app.core.plugin_system import ProxyRaw
|
|
from app.plugins.base import BaseHTTPPlugin
|
|
from app.core.log import logger
|
|
|
|
|
|
class SpeedXPlugin(BaseHTTPPlugin):
|
|
name = "speedx"
|
|
display_name = "SpeedX代理源"
|
|
description = "从 SpeedX GitHub 仓库获取 SOCKS 代理列表"
|
|
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.urls = [
|
|
"https://raw.githubusercontent.com/TheSpeedX/SOCKS-List/master/http.txt",
|
|
"https://raw.githubusercontent.com/TheSpeedX/SOCKS-List/master/socks4.txt",
|
|
"https://raw.githubusercontent.com/TheSpeedX/SOCKS-List/master/socks5.txt",
|
|
]
|
|
|
|
async def crawl(self) -> List[ProxyRaw]:
|
|
results = []
|
|
for url in self.urls:
|
|
html = await self.fetch(url, timeout=30)
|
|
if not html:
|
|
continue
|
|
|
|
# 根据 URL 判断协议
|
|
protocol = "http"
|
|
if "socks5" in url:
|
|
protocol = "socks5"
|
|
elif "socks4" in url:
|
|
protocol = "socks4"
|
|
|
|
for line in html.split("\n"):
|
|
line = line.strip()
|
|
if not line or ":" not in line:
|
|
continue
|
|
parts = line.split(":")
|
|
if len(parts) >= 2:
|
|
ip = parts[0].strip()
|
|
port = parts[1].strip()
|
|
if not re.match(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$", ip):
|
|
continue
|
|
if not port.isdigit() or not (1 <= int(port) <= 65535):
|
|
continue
|
|
results.append(ProxyRaw(ip, int(port), protocol))
|
|
|
|
if results:
|
|
logger.info(f"{self.display_name} 解析完成,获得 {len(results)} 个潜在代理")
|
|
return results
|