返回提交历史
Modified
src/controllers/custom/addItemsController.ts
+19
-10
Modified
static/webui/script.js
+16
-8
XFEstudio/XFESpaceNinjaServer
chore(webui): let user know of item acquisition errors (#3260)
Closes #3258 Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/3260 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
8209ce38
代码差异
2 个文件
+35
-18
@@ -2,6 +2,7 @@ import { getAccountForRequest } from "../../services/loginService.ts";
2
2
import { getInventory, addItem } from "../../services/inventoryService.ts";
3
3
import type { RequestHandler } from "express";
4
4
import { broadcastInventoryUpdate } from "../../services/wsService.ts";
5
import { logger } from "../../utils/logger.ts";
5
6
6
7
export const addItemsController: RequestHandler = async (req, res) => {
7
8
const account = await getAccountForRequest(req);
@@ -9,16 +10,24 @@ export const addItemsController: RequestHandler = async (req, res) => {
9
10
const requests = req.body as IAddItemRequest[];
10
11
const inventory = await getInventory(accountId);
11
12
for (const request of requests) {
12
await addItem(
13
inventory,
14
request.ItemType,
15
request.ItemCount,
16
true,
17
undefined,
18
request.Fingerprint,
19
true,
20
account.BuildLabel
21
);
13
try {
14
await addItem(
15
inventory,
16
request.ItemType,
17
request.ItemCount,
18
true,
19
undefined,
20
request.Fingerprint,
21
true,
22
account.BuildLabel
23
);
24
} catch (e) {
25
logger.debug(`AddItemRequest ${JSON.stringify(request)} failed: ${(e as Error).message}`);
26
res.status(500)
27
.send((e as Error).message)
28
.end();
29
return;
30
}
22
31
}
23
32
if (inventory.isModified()) {
24
33
await inventory.save();
@@ -2964,14 +2964,22 @@ function doAcquireCountItems(category) {
2964
2964
ItemCount: count
2965
2965
}
2966
2966
])
2967
}).done(function () {
2968
if (count > 0) {
2969
toast(loc("code_succAdded"));
2970
} else {
2971
toast(loc("code_succRemoved"));
2972
}
2973
if (category != "miscitems") updateInventory();
2974
});
2967
})
2968
.done(function (didAnything) {
2969
if (didAnything) {
2970
if (count > 0) {
2971
toast(loc("code_succAdded"));
2972
} else {
2973
toast(loc("code_succRemoved"));
2974
}
2975
} else {
2976
toast(loc("code_nothingToDo"));
2977
}
2978
if (category != "miscitems") updateInventory();
2979
})
2980
.fail(r => {
2981
toast(r.responseText);
2982
});
2975
2983
});
2976
2984
}
2977
2985
}