fix(upload): 修复上传文件问题

This commit is contained in:
2026-05-01 22:46:06 +08:00
parent 7c01ecaf60
commit 92cb9901fb
3 changed files with 34 additions and 13 deletions

View File

@@ -1,10 +1,11 @@
"""消息发送处理器JSON 解析、参数校验、QQ API 超时与重试。"""
import asyncio
from pathlib import Path
from aiohttp import web
from ..config import QQ_API_MAX_RETRIES, QQ_API_TIMEOUT
from ..config import QQ_API_MAX_RETRIES, QQ_API_TIMEOUT, UPLOAD_DIR
from ..response import error, ok
VALID_MSG_TYPES = {"text", "image", "file", "video"}
@@ -80,6 +81,11 @@ async def webhook_handler(request: web.Request) -> web.Response:
msg = data.get("msg", "")
url = data.get("url", "")
# 如果 url 是本地已上传的文件(相对路径),补全为绝对路径
file_path = Path(url)
if not file_path.is_absolute() and (UPLOAD_DIR / url).exists():
url = str((UPLOAD_DIR / url).resolve())
# 获取 ncatbot API 实例
api = request.app["qq_api"]