chore(webui): give feedback when import errored (#3044)
Closes #3043 Reviewed-on: #3044 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
This commit was merged in pull request #3044.
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -3646,8 +3646,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) {
|
||||
|
||||
Reference in New Issue
Block a user