返回提交历史
Modified
src/controllers/custom/addItemController.ts
+4
-2
Modified
src/helpers/customHelpers/addItemHelpers.ts
+2
-4
Modified
static/webui/script.js
+4
-6
XFEstudio/SpaceNinjaServer
improve: authenticate addItem requests (#242)
bc21a4d2
代码差异
3 个文件
+10
-12
@@ -1,3 +1,4 @@
1
import { getAccountIdForRequest } from "@/src/services/loginService";
1
2
import { ItemType, toAddItemRequest } from "@/src/helpers/customHelpers/addItemHelpers";
2
3
import { getWeaponType } from "@/src/services/itemDataService";
3
4
import { addPowerSuit, addWeapon } from "@/src/services/inventoryService";
@@ -5,16 +6,17 @@ import { RequestHandler } from "express";
5
6
6
7
// eslint-disable-next-line @typescript-eslint/no-misused-promises
7
8
const addItemController: RequestHandler = async (req, res) => {
9
const accountId = await getAccountIdForRequest(req);
8
10
const request = toAddItemRequest(req.body);
9
11
10
12
switch (request.type) {
11
13
case ItemType.Powersuit:
12
const powersuit = await addPowerSuit(request.InternalName, request.accountId);
14
const powersuit = await addPowerSuit(request.InternalName, accountId);
13
15
res.json(powersuit);
14
16
return;
15
17
case ItemType.Weapon:
16
18
const weaponType = getWeaponType(request.InternalName);
17
const weapon = await addWeapon(weaponType, request.InternalName, request.accountId);
19
const weapon = await addWeapon(weaponType, request.InternalName, accountId);
18
20
res.json(weapon);
19
21
break;
20
22
default:
@@ -21,7 +21,6 @@ const parseItemType = (itemType: unknown): ItemType => {
21
21
interface IAddItemRequest {
22
22
type: ItemType;
23
23
InternalName: string;
24
accountId: string;
25
24
}
26
25
export const isInternalItemName = (internalName: string): boolean => {
27
26
const item = items.find(i => i.uniqueName === internalName);
@@ -41,11 +40,10 @@ export const toAddItemRequest = (body: unknown): IAddItemRequest => {
41
40
throw new Error("incorrect or missing add item request data");
42
41
}
43
42
44
if ("type" in body && "internalName" in body && "accountId" in body) {
43
if ("type" in body && "internalName" in body) {
45
44
return {
46
45
type: parseItemType(body.type),
47
InternalName: parseInternalItemName(body.internalName),
48
accountId: parseString(body.accountId)
46
InternalName: parseInternalItemName(body.internalName)
49
47
};
50
48
}
51
49
@@ -266,12 +266,11 @@ function doAcquireWarframe() {
266
266
}
267
267
revalidateAuthz(() => {
268
268
const req = $.post({
269
url: "/custom/addItem",
269
url: "/custom/addItem?" + window.authz,
270
270
contentType: "application/json",
271
271
data: JSON.stringify({
272
272
type: "Powersuit",
273
internalName: uniqueName,
274
accountId: window.accountId
273
internalName: uniqueName
275
274
})
276
275
});
277
276
req.done(() => {
@@ -293,12 +292,11 @@ function doAcquireWeapon() {
293
292
}
294
293
revalidateAuthz(() => {
295
294
const req = $.post({
296
url: "/custom/addItem",
295
url: "/custom/addItem?" + window.authz,
297
296
contentType: "application/json",
298
297
data: JSON.stringify({
299
298
type: "Weapon",
300
internalName: uniqueName,
301
accountId: window.accountId
299
internalName: uniqueName
302
300
})
303
301
});
304
302
req.done(() => {