XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

SpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 1 Star 0
返回提交历史

XFEstudio/SpaceNinjaServer

chore: handle purchase request from U16 (#3830)

Closes #3829 Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/3830 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>

c0e41315
Sainan <63328889+Sainan@users.noreply.github.com>
提交于

代码差异

2 个文件 +25 -10
Modified src/controllers/api/purchaseController.ts +19 -10
@@ -1,7 +1,7 @@
1 1 import type { RequestHandler } from "express";
2 2 import { getAccountForRequest } from "../../services/loginService.ts";
3 3 import { PurchaseSource } from "../../types/purchaseTypes.ts";
4 import type { IPurchaseRequest } from "../../types/purchaseTypes.ts";
4 import type { IPurchaseRequest, IPurchaseRequestU16 } from "../../types/purchaseTypes.ts";
5 5 import { handlePurchase } from "../../services/purchaseService.ts";
6 6 import { getInventory } from "../../services/inventoryService.ts";
7 7 import { sendWsBroadcastTo } from "../../services/wsService.ts";
@@ -9,23 +9,32 @@ import { toStoreItem } from "../../services/itemDataService.ts";
9 9 import { ExportBundles } from "warframe-public-export-plus";
10 10 import { version_compare } from "../../helpers/inventoryHelpers.ts";
11 11 import gameToBuildVersion from "../../constants/gameToBuildVersion.ts";
12 import { logger } from "../../utils/logger.ts";
12 13
13 14 export const purchasePostController: RequestHandler = async (req, res) => {
14 const purchaseRequest = JSON.parse(String(req.body)) as IPurchaseRequest;
15 let purchaseRequest = JSON.parse(String(req.body)) as IPurchaseRequest | IPurchaseRequestU16;
16 if (!("PurchaseParams" in purchaseRequest)) {
17 logger.debug("converting legacy purchase request", purchaseRequest);
18 purchaseRequest = {
19 PurchaseParams: {
20 Source: PurchaseSource.Market,
21 StoreItem: toStoreItem(purchaseRequest.productName),
22 Quantity: purchaseRequest.quantity,
23 UsePremium: purchaseRequest.usePremium == "1"
24 },
25 buildLabel: ""
26 } satisfies IPurchaseRequest;
27 }
15 28 const account = await getAccountForRequest(req);
16 if (!purchaseRequest.buildLabel && account.BuildLabel) purchaseRequest.buildLabel = account.BuildLabel;
17 if (purchaseRequest.buildLabel && account.BuildLabel && purchaseRequest.buildLabel != account.BuildLabel) {
18 throw new Error(
19 `account logged into ${account.BuildLabel} but is now attempting a purchase in ${purchaseRequest.buildLabel} ?!`
20 );
29 if (!purchaseRequest.buildLabel) {
30 purchaseRequest.buildLabel = account.BuildLabel!;
21 31 }
22 const accountId = account._id.toString();
23 const inventory = await getInventory(accountId);
32 const inventory = await getInventory(account._id);
24 33 const response = await handlePurchase(purchaseRequest, inventory);
25 34 await inventory.save();
26 35 //console.log(JSON.stringify(response, null, 2));
27 36 res.json(response);
28 sendWsBroadcastTo(accountId, { update_inventory: true });
37 sendWsBroadcastTo(account._id.toString(), { update_inventory: true });
29 38 };
30 39
31 40 export const purchaseGetController: RequestHandler = async (req, res) => {
Modified src/types/purchaseTypes.ts +6 -0
@@ -49,6 +49,12 @@ export interface IPurchaseRequest {
49 49 buildLabel: string;
50 50 }
51 51
52 export interface IPurchaseRequestU16 {
53 productName: string;
54 quantity: number;
55 usePremium: "1" | "0";
56 }
57
52 58 export interface IPurchaseParams {
53 59 Source: PurchaseSource;
54 60 SourceId?: string; // VoidTrader, Vendor, PrimeVaultTrader