fix(admin): harden clothing/pets/effects/clone imports

Align grids on data.items, only treat SSE done as success, hard-fail
clothing sets when libs fail, and add Cancel via AbortController.

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
SimoandCursor committed 2026-08-01 15:56:38 +02:00
1 parent 9c4949186c
commit 16191cef14
8 files changed
+344 -173

No files matched your search

@@ -87,4 +87,20 @@ describe("importClothingSet", () => {
const r = await importClothingSet({ setType: "ch", setId: 999999 });
expect(r.ok).toBe(false);
});
it("does not write set data when a required library import fails", async () => {
mergeSet.mockClear();
mergePalette.mockClear();
importSingleFigure.mockResolvedValueOnce({
ok: false,
lib: "shirt_M_x",
warnings: [],
error: "nitro missing",
});
const r = await importClothingSet({ setType: "ch", setId: 5000 });
expect(r.ok).toBe(false);
expect(r.error).toMatch(/required figure libraries failed/i);
expect(mergeSet).not.toHaveBeenCalled();
expect(mergePalette).not.toHaveBeenCalled();
});
});
+15
View File
@@ -133,6 +133,8 @@ export async function importClothingSet(params: {
await ensureFigureDirs();
let hardFail = false;
for (const libId of requiredLibIds) {
const officialLib = officialLibs.find((l) => l.id === libId);
if (!officialLib) continue;
@@ -141,18 +143,31 @@ export async function importClothingSet(params: {
onProgress?.(`importing library ${libId}`);
const result = await importSingleFigure({ lib: libId, onProgress });
if (!result.ok) {
hardFail = true;
warnings.push(
`Library import failed for ${libId}: ${result.error ?? "unknown error"}`,
);
continue;
}
if (result.warnings.length) {
warnings.push(...result.warnings);
}
localLibIds.add(libId);
}
await mergeLibrary(officialLib);
}
if (hardFail) {
return {
ok: false,
setId,
warnings,
error:
"One or more required figure libraries failed to import — set was not written",
};
}
const mappedSet = mapOfficialSet(set);
await mergeSet(setType, st.paletteId, mappedSet as never);