fix(upload): 修复上传文件问题
This commit is contained in:
@@ -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"]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user