返回提交历史
Modified
src/controllers/custom/importController.ts
+31
-23
Modified
static/webui/script.js
+6
-2
XFEstudio/XFESpaceNinjaServer
chore(webui): give feedback when import errored (#3044)
Closes #3043 Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/3044 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
974636b5
代码差异
2 个文件
+37
-25
@@ -13,33 +13,41 @@ export const importController: RequestHandler = async (req, res) => {
13
13
const request = req.body as IImportRequest;
14
14
15
15
let anyKnownKey = false;
16
try {
17
const inventory = await getInventory(accountId);
18
if (importInventory(inventory, request.inventory)) {
19
anyKnownKey = true;
20
await inventory.save();
21
}
16
22
17
const inventory = await getInventory(accountId);
18
if (importInventory(inventory, request.inventory)) {
19
anyKnownKey = true;
20
await inventory.save();
21
}
23
if ("LoadOutPresets" in request.inventory && request.inventory.LoadOutPresets) {
24
anyKnownKey = true;
25
const loadout = await getLoadout(accountId);
26
importLoadOutPresets(loadout, request.inventory.LoadOutPresets);
27
await loadout.save();
28
}
22
29
23
if ("LoadOutPresets" in request.inventory && request.inventory.LoadOutPresets) {
24
anyKnownKey = true;
25
const loadout = await getLoadout(accountId);
26
importLoadOutPresets(loadout, request.inventory.LoadOutPresets);
27
await loadout.save();
28
}
30
if (
31
request.inventory.Ship?.Rooms || // very old accounts may have Ship with { Features: [ ... ] }
32
"Apartment" in request.inventory ||
33
"TailorShop" in request.inventory
34
) {
35
anyKnownKey = true;
36
const personalRooms = await getPersonalRooms(accountId);
37
importPersonalRooms(personalRooms, request.inventory);
38
await personalRooms.save();
39
}
29
40
30
if (
31
request.inventory.Ship?.Rooms || // very old accounts may have Ship with { Features: [ ... ] }
32
"Apartment" in request.inventory ||
33
"TailorShop" in request.inventory
34
) {
35
anyKnownKey = true;
36
const personalRooms = await getPersonalRooms(accountId);
37
importPersonalRooms(personalRooms, request.inventory);
38
await personalRooms.save();
39
}
41
if (!anyKnownKey) {
42
res.send("noKnownKey").end();
43
}
40
44
41
res.json(anyKnownKey);
42
broadcastInventoryUpdate(req);
45
broadcastInventoryUpdate(req);
46
} catch (e) {
47
console.error(e);
48
res.send((e as Error).message);
49
}
50
res.end();
43
51
};
44
52
45
53
interface IImportRequest {
@@ -3646,8 +3646,12 @@ function doImport() {
3646
3646
data: JSON.stringify({
3647
3647
inventory: JSON.parse($("#import-inventory").val())
3648
3648
})
3649
}).then(function (anyKnownKey) {
3650
toast(loc(anyKnownKey ? "code_succImport" : "code_nothingToDo"));
3649
}).then(function (err) {
3650
if (err) {
3651
toast(err == "noKnownKey" ? loc("code_nothingToDo") : err);
3652
} else {
3653
toast(loc("code_succImport"));
3654
}
3651
3655
updateInventory();
3652
3656
});
3653
3657
} catch (e) {