chore(webui): give feedback when import errored
All checks were successful
Build / build (pull_request) Successful in 1m13s

This commit is contained in:
2025-11-18 10:36:59 +01:00
parent 34ba56862b
commit f1a17f7b7f
2 changed files with 39 additions and 27 deletions

View File

@@ -13,33 +13,41 @@ export const importController: RequestHandler = async (req, res) => {
const request = req.body as IImportRequest;
let anyKnownKey = false;
try {
const inventory = await getInventory(accountId);
if (importInventory(inventory, request.inventory)) {
anyKnownKey = true;
await inventory.save();
}
const inventory = await getInventory(accountId);
if (importInventory(inventory, request.inventory)) {
anyKnownKey = true;
await inventory.save();
if ("LoadOutPresets" in request.inventory && request.inventory.LoadOutPresets) {
anyKnownKey = true;
const loadout = await getLoadout(accountId);
importLoadOutPresets(loadout, request.inventory.LoadOutPresets);
await loadout.save();
}
if (
request.inventory.Ship?.Rooms || // very old accounts may have Ship with { Features: [ ... ] }
"Apartment" in request.inventory ||
"TailorShop" in request.inventory
) {
anyKnownKey = true;
const personalRooms = await getPersonalRooms(accountId);
importPersonalRooms(personalRooms, request.inventory);
await personalRooms.save();
}
if (!anyKnownKey) {
res.send("noKnownKey").end();
}
broadcastInventoryUpdate(req);
} catch (e) {
console.error(e);
res.send((e as Error).message);
}
if ("LoadOutPresets" in request.inventory && request.inventory.LoadOutPresets) {
anyKnownKey = true;
const loadout = await getLoadout(accountId);
importLoadOutPresets(loadout, request.inventory.LoadOutPresets);
await loadout.save();
}
if (
request.inventory.Ship?.Rooms || // very old accounts may have Ship with { Features: [ ... ] }
"Apartment" in request.inventory ||
"TailorShop" in request.inventory
) {
anyKnownKey = true;
const personalRooms = await getPersonalRooms(accountId);
importPersonalRooms(personalRooms, request.inventory);
await personalRooms.save();
}
res.json(anyKnownKey);
broadcastInventoryUpdate(req);
res.end();
};
interface IImportRequest {

View File

@@ -3625,8 +3625,12 @@ function doImport() {
data: JSON.stringify({
inventory: JSON.parse($("#import-inventory").val())
})
}).then(function (anyKnownKey) {
toast(loc(anyKnownKey ? "code_succImport" : "code_nothingToDo"));
}).then(function (err) {
if (err) {
toast(err == "noKnownKey" ? loc("code_nothingToDo") : err);
} else {
toast(loc("code_succImport"));
}
updateInventory();
});
} catch (e) {