Prefer root asset pack manifests

这个提交存在于:
YokiiroBW 2026-07-05 20:16:10 +08:00
父节点 d80d23c3dc
当前提交 d61dbfd3a4
共有 2 个文件被更改,包括 29 次插入 和 5 次删除

查看文件

@ -12,6 +12,11 @@ from core.storage import VfsStorage
_MANIFEST_FILENAMES = {"manifest.json", "imagestudio-pack.json", "pack.json"}
_MANIFEST_FILENAME_PRIORITY = {
"imagestudio-pack.json": 0,
"manifest.json": 1,
"pack.json": 2,
}
class AssetImportService:
@ -49,14 +54,29 @@ class AssetImportService:
def _manifest_candidates(root: str, relative: Path, package_path: Path) -> list[dict[str, Any]]:
if package_path.is_file():
return [{"uri": _storage_uri(root, relative), "path": package_path}] if package_path.name in _MANIFEST_FILENAMES else []
return (
[{"uri": _storage_uri(root, relative), "path": package_path, "relative": Path(package_path.name)}]
if package_path.name in _MANIFEST_FILENAMES
else []
)
candidates: list[dict[str, Any]] = []
for child in package_path.rglob("*"):
if child.is_file() and child.name in _MANIFEST_FILENAMES:
child_relative = relative / child.relative_to(package_path)
candidates.append({"uri": _storage_uri(root, child_relative), "path": child})
return sorted(candidates, key=lambda item: item["uri"])
pack_relative = child.relative_to(package_path)
child_relative = relative / pack_relative
candidates.append({"uri": _storage_uri(root, child_relative), "path": child, "relative": pack_relative})
return sorted(candidates, key=_manifest_sort_key)
def _manifest_sort_key(item: dict[str, Any]) -> tuple[int, int, str]:
relative = item["relative"]
filename = relative.name
return (
len(relative.parts),
_MANIFEST_FILENAME_PRIORITY.get(filename, 99),
item["uri"],
)
def _manifest_summary(package_path: Path, candidates: list[dict[str, Any]]) -> dict[str, Any]:

查看文件

@ -681,6 +681,9 @@ database:
pack.mkdir(parents=True, exist_ok=True)
(pack / "manifest.json").write_text('{"name":"demo"}', encoding="utf-8")
(pack / "image.bin").write_bytes(b"123")
nested = pack / "nested"
nested.mkdir(parents=True, exist_ok=True)
(nested / "imagestudio-pack.json").write_text('{"name":"nested"}', encoding="utf-8")
planned = import_asset_pack(
self.ctx,
@ -690,7 +693,8 @@ database:
self.assertTrue(planned["ok"])
self.assertTrue(planned["data"]["dry_run"])
self.assertEqual(planned["data"]["files"], 2)
self.assertEqual(planned["data"]["files"], 3)
self.assertEqual(planned["data"]["manifest_candidates"][0], "storage://materials/pack/manifest.json")
self.assertIn("storage://materials/pack/manifest.json", planned["data"]["manifest_candidates"])
self.assertTrue(planned["data"]["manifest"]["valid"])
self.assertEqual(planned["data"]["manifest"]["name"], "demo")