fix(async): offload file metadata checks

This commit is contained in:
InfinityPacer
2026-08-23 12:06:52 +08:00
parent 56293bc82a
commit e8cfe272c4
9 changed files with 182 additions and 12 deletions
+10 -1
View File
@@ -8,6 +8,7 @@ from urllib.parse import quote
import discord
from discord import app_commands
import httpx
from fastapi.concurrency import run_in_threadpool
from app.runtime.settings import RuntimeSettingsCompat
@@ -28,6 +29,11 @@ PARSE_FIELD_TYPES = {
}
def _is_regular_file(path: Path) -> bool:
"""判断路径是否仍指向可发送的普通文件。"""
return path.exists() and path.is_file()
class Discord:
"""
Discord Bot 通知与交互实现(基于 discord.py 2.6.4
@@ -780,7 +786,10 @@ class Discord:
return False, None
local_file = Path(file_path)
if not local_file.exists() or not local_file.is_file():
if not await run_in_threadpool(
_is_regular_file,
local_file,
):
logger.error(f"Discord发送文件失败,文件不存在: {local_file}")
return False, None