P2: 清理与一致性
- CLI: --preset 实际生效;--directory-listing/--enable-stats/--enable-*/--ignore-hidden 支持 true/false(修复 type=bool 陷阱),未显式传入时不再覆盖 settings.json - 版本号统一 v2.3(settings.json/config.py/v1/v2/Dockerfile) - 移除硬编码 /tmp/pypi_debug.log 写文件;v2 裸 except 改记录错误返回 500 - webhook id 非法输入返回 400;下载趋势 timedelta 导入提升修复 NameError - 打包模式 auth_token 写入 exe 目录(不再写入 _MEIPASS) - README 修正: 线程池架构、pyinstaller 构建方式 - mirrors/__init__.py ' Quay.io' 笔误;chunked 响应去掉 Content-Length;docs/ui realpath 边界 - SQLite WAL+busy_timeout;下载计数原子 UPDATE - requirements 移除未使用的 cachetools/apscheduler
This commit is contained in:
@@ -597,11 +597,6 @@ class APIv2(APIv1):
|
||||
# 获取镜像类型
|
||||
mirror_type = mirror_config.get('type', 'http')
|
||||
|
||||
# 调试
|
||||
debug_file = '/tmp/pypi_debug.log'
|
||||
with open(debug_file, 'a') as f:
|
||||
f.write(f"[V2] mirror_type={mirror_type}, handler_class={get_mirror_handler(mirror_type)}\n")
|
||||
|
||||
# 获取处理器类
|
||||
handler_class = get_mirror_handler(mirror_type)
|
||||
if not handler_class:
|
||||
@@ -887,8 +882,17 @@ class APIv2(APIv1):
|
||||
# v2 端点都没匹配到,尝试调用 APIv1
|
||||
try:
|
||||
return super().handle_request(handler, method, path, query_params)
|
||||
except:
|
||||
pass
|
||||
except Exception as e:
|
||||
# 记录真实错误而非吞掉(避免 v1 内部异常被误报为 404)
|
||||
if handler._is_debug_enabled('error'):
|
||||
import traceback
|
||||
handler._debug_log('error', f"APIv1 处理失败 ({path}): {e}\n{traceback.format_exc()}")
|
||||
handler.send_json_response({
|
||||
"error": f"API处理错误: {str(e)}",
|
||||
"version": "v1",
|
||||
"path": path
|
||||
}, 500)
|
||||
return
|
||||
|
||||
# 404 - 未找到端点
|
||||
handler.send_error(404)
|
||||
@@ -1283,6 +1287,8 @@ class APIv2(APIv1):
|
||||
def api_get_download_trend(self, handler, query_params):
|
||||
"""获取下载趋势(按天统计)"""
|
||||
days = int(query_params.get('days', [7])[0])
|
||||
from datetime import timedelta # 供数据库与回退分支共同使用
|
||||
|
||||
days = min(max(days, 1), 90) # 限制 1-90 天
|
||||
|
||||
trend = []
|
||||
@@ -1291,7 +1297,6 @@ class APIv2(APIv1):
|
||||
db = self.get_db()
|
||||
if db:
|
||||
try:
|
||||
from datetime import timedelta
|
||||
from core.database import DownloadRecord
|
||||
|
||||
now = datetime.now()
|
||||
@@ -1983,7 +1988,11 @@ class APIv2(APIv1):
|
||||
|
||||
def api_get_webhook(self, handler, webhook_id):
|
||||
"""获取webhook详情"""
|
||||
webhook_id = int(webhook_id)
|
||||
try:
|
||||
webhook_id = int(webhook_id)
|
||||
except (ValueError, TypeError):
|
||||
handler.send_json_response({"error": "Invalid webhook id"}, 400)
|
||||
return
|
||||
|
||||
if self.db_enabled and self.db:
|
||||
try:
|
||||
@@ -2006,7 +2015,11 @@ class APIv2(APIv1):
|
||||
|
||||
def api_delete_webhook(self, handler, webhook_id):
|
||||
"""删除webhook"""
|
||||
webhook_id = int(webhook_id)
|
||||
try:
|
||||
webhook_id = int(webhook_id)
|
||||
except (ValueError, TypeError):
|
||||
handler.send_json_response({"error": "Invalid webhook id"}, 400)
|
||||
return
|
||||
|
||||
if self.db_enabled and self.db:
|
||||
try:
|
||||
@@ -2031,7 +2044,11 @@ class APIv2(APIv1):
|
||||
|
||||
def api_test_webhook(self, handler, webhook_id):
|
||||
"""测试webhook"""
|
||||
webhook_id = int(webhook_id)
|
||||
try:
|
||||
webhook_id = int(webhook_id)
|
||||
except (ValueError, TypeError):
|
||||
handler.send_json_response({"error": "Invalid webhook id"}, 400)
|
||||
return
|
||||
|
||||
if self.db_enabled and self.db:
|
||||
try:
|
||||
@@ -2095,7 +2112,11 @@ class APIv2(APIv1):
|
||||
|
||||
def api_get_webhook_deliveries(self, handler, webhook_id):
|
||||
"""获取 webhook 交付历史"""
|
||||
webhook_id = int(webhook_id)
|
||||
try:
|
||||
webhook_id = int(webhook_id)
|
||||
except (ValueError, TypeError):
|
||||
handler.send_json_response({"error": "Invalid webhook id"}, 400)
|
||||
return
|
||||
|
||||
# 验证 webhook 存在
|
||||
if self.db_enabled and self.db:
|
||||
@@ -2126,7 +2147,11 @@ class APIv2(APIv1):
|
||||
|
||||
def api_get_webhook_stats(self, handler, webhook_id):
|
||||
"""获取 webhook 交付统计"""
|
||||
webhook_id = int(webhook_id)
|
||||
try:
|
||||
webhook_id = int(webhook_id)
|
||||
except (ValueError, TypeError):
|
||||
handler.send_json_response({"error": "Invalid webhook id"}, 400)
|
||||
return
|
||||
|
||||
if self.db_enabled and self.db:
|
||||
try:
|
||||
@@ -2146,7 +2171,11 @@ class APIv2(APIv1):
|
||||
|
||||
def api_update_webhook(self, handler, webhook_id):
|
||||
"""更新 webhook 配置"""
|
||||
webhook_id = int(webhook_id)
|
||||
try:
|
||||
webhook_id = int(webhook_id)
|
||||
except (ValueError, TypeError):
|
||||
handler.send_json_response({"error": "Invalid webhook id"}, 400)
|
||||
return
|
||||
|
||||
content_length = int(handler.headers.get('Content-Length', 0))
|
||||
if content_length == 0:
|
||||
@@ -3741,7 +3770,7 @@ class APIv2(APIv1):
|
||||
|
||||
handler.send_json_response({
|
||||
"name": self.config.get('server_name', 'HYC下载站'),
|
||||
"version": "2.2.0",
|
||||
"version": "2.3.0",
|
||||
"uptime_seconds": round(uptime_seconds, 2),
|
||||
"uptime_formatted": uptime_str,
|
||||
"api_version": "v2",
|
||||
|
||||
Reference in New Issue
Block a user