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
+15 -2
View File
@@ -26,6 +26,12 @@ from app.domain.media import normalize_music_type
from ._music_utils import simplify_music_info
def _inspect_local_path(path: Path) -> tuple[bool, bool]:
"""返回本地路径是否存在及是否为目录。"""
exists = path.exists()
return exists and path.is_dir(), exists
class ScrapeMetadataInput(BaseModel):
"""刮削媒体元数据工具的输入参数模型"""
@@ -151,7 +157,14 @@ class ScrapeMetadataTool(MoviePilotTool):
media_id = normalized_media_id or None
local_path = Path(path)
is_local_directory = (storage or "local") == "local" and local_path.is_dir()
is_local_directory = False
path_exists = True
if (storage or "local") == "local":
is_local_directory, path_exists = await self.run_blocking(
"storage",
_inspect_local_path,
local_path,
)
file_type = "dir" if is_local_directory or not local_path.suffix else "file"
fileitem = FileItem(
storage=storage or "local",
@@ -161,7 +174,7 @@ class ScrapeMetadataTool(MoviePilotTool):
# 检查本地存储路径是否存在
if storage == "local":
if not Path(path).exists():
if not path_exists:
return json.dumps(
{"success": False, "message": f"刮削路径不存在: {path}"},
ensure_ascii=False,