From 92cb9901fbc0ec95dccc1361a370c4b79e3263d2 Mon Sep 17 00:00:00 2001 From: zhilv Date: Fri, 1 May 2026 22:46:06 +0800 Subject: [PATCH] =?UTF-8?q?fix(upload):=20=E4=BF=AE=E5=A4=8D=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E6=96=87=E4=BB=B6=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- handlers/message.py | 8 +++++++- pyproject.toml | 2 +- uv.lock | 37 ++++++++++++++++++++++++++----------- 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/handlers/message.py b/handlers/message.py index 6fc19f5..2afa656 100644 --- a/handlers/message.py +++ b/handlers/message.py @@ -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"] diff --git a/pyproject.toml b/pyproject.toml index 15737d6..4e87235 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [project] -name = "Webhook Plugin" +name = "WebhookPlugin" version = "0.1.1" description = "将发消息的接口代理出来" readme = "README.md" diff --git a/uv.lock b/uv.lock index 9f51dc9..695243e 100644 --- a/uv.lock +++ b/uv.lock @@ -449,17 +449,6 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/81/08/7036c080d7117f28a4af526d794aab6a84463126db031b007717c1a6676e/multidict-6.7.1-py3-none-any.whl", hash = "sha256:55d97cc6dae627efa6a6e548885712d4864b81110ac76fa4e534c03819fa4a56", size = 12319, upload-time = "2026-01-26T02:46:44.004Z" }, ] -[[package]] -name = "ncatbot-demo" -version = "0.1.0" -source = { virtual = "." } -dependencies = [ - { name = "ncatbot5" }, -] - -[package.metadata] -requires-dist = [{ name = "ncatbot5", specifier = ">=5.5.2.post3" }] - [[package]] name = "ncatbot5" version = "5.5.2.post3" @@ -735,6 +724,15 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/d8/db/795879cc3ddfe338599bddea6388cc5100b088db0a4caf6e6c1af1c27e04/python_discovery-1.2.2-py3-none-any.whl", hash = "sha256:e1ae95d9af875e78f15e19aed0c6137ab1bb49c200f21f5061786490c9585c7a", size = 31894, upload-time = "2026-04-07T17:28:48.09Z" }, ] +[[package]] +name = "python-dotenv" +version = "1.2.2" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/82/ed/0301aeeac3e5353ef3d94b6ec08bbcabd04a72018415dcb29e588514bba8/python_dotenv-1.2.2.tar.gz", hash = "sha256:2c371a91fbd7ba082c2c1dc1f8bf89ca22564a087c2c287cd9b662adde799cf3", size = 50135, upload-time = "2026-03-01T16:00:26.196Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/0b/d7/1959b9648791274998a9c3526f6d0ec8fd2233e4d4acce81bbae76b44b2a/python_dotenv-1.2.2-py3-none-any.whl", hash = "sha256:1d8214789a24de455a8b8bd8ae6fe3c6b69a5e3d64aa8a8e5d68e694bbcb285a", size = 22101, upload-time = "2026-03-01T16:00:25.09Z" }, +] + [[package]] name = "pyyaml" version = "6.0.3" @@ -905,6 +903,23 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/4b/eb/03bfb1299d4c4510329e470f13f9a4ce793df7fcb5a2fd3510f911066f61/virtualenv-21.3.0-py3-none-any.whl", hash = "sha256:4d28ee41f6d9ec8f1f00cd472b9ffbcedda1b3d3b9a575b5c94a2d004fd51bd7", size = 7594690, upload-time = "2026-04-27T17:05:55.468Z" }, ] +[[package]] +name = "webhookplugin" +version = "0.1.1" +source = { virtual = "." } +dependencies = [ + { name = "aiohttp" }, + { name = "ncatbot5" }, + { name = "python-dotenv" }, +] + +[package.metadata] +requires-dist = [ + { name = "aiohttp", specifier = ">=3.9" }, + { name = "ncatbot5", specifier = ">=5.5.2.post3" }, + { name = "python-dotenv", specifier = ">=1.0" }, +] + [[package]] name = "websockets" version = "16.0"