mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-04 23:17:20 +08:00
fix(async): offload file metadata checks
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user