fix(upload): 修复上传文件问题
This commit is contained in:
@@ -1,10 +1,11 @@
|
|||||||
"""消息发送处理器:JSON 解析、参数校验、QQ API 超时与重试。"""
|
"""消息发送处理器:JSON 解析、参数校验、QQ API 超时与重试。"""
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
from aiohttp import web
|
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
|
from ..response import error, ok
|
||||||
|
|
||||||
VALID_MSG_TYPES = {"text", "image", "file", "video"}
|
VALID_MSG_TYPES = {"text", "image", "file", "video"}
|
||||||
@@ -80,6 +81,11 @@ async def webhook_handler(request: web.Request) -> web.Response:
|
|||||||
msg = data.get("msg", "")
|
msg = data.get("msg", "")
|
||||||
url = data.get("url", "")
|
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 实例
|
# 获取 ncatbot API 实例
|
||||||
api = request.app["qq_api"]
|
api = request.app["qq_api"]
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "Webhook Plugin"
|
name = "WebhookPlugin"
|
||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
description = "将发消息的接口代理出来"
|
description = "将发消息的接口代理出来"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
|||||||
37
uv.lock
generated
37
uv.lock
generated
@@ -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" },
|
{ 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]]
|
[[package]]
|
||||||
name = "ncatbot5"
|
name = "ncatbot5"
|
||||||
version = "5.5.2.post3"
|
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" },
|
{ 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]]
|
[[package]]
|
||||||
name = "pyyaml"
|
name = "pyyaml"
|
||||||
version = "6.0.3"
|
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" },
|
{ 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]]
|
[[package]]
|
||||||
name = "websockets"
|
name = "websockets"
|
||||||
version = "16.0"
|
version = "16.0"
|
||||||
|
|||||||
Reference in New Issue
Block a user