From 3cd66391b6e1f7aba9fd541ff1caf032b8fe7e28 Mon Sep 17 00:00:00 2001 From: Sainan Date: Fri, 24 Jan 2025 15:44:34 +0100 Subject: [PATCH 1/4] fix(webui): max rank (#859) --- src/controllers/custom/addXpController.ts | 20 ++++++++++++++++++++ src/routes/custom.ts | 2 ++ static/webui/script.js | 13 +++++-------- 3 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 src/controllers/custom/addXpController.ts diff --git a/src/controllers/custom/addXpController.ts b/src/controllers/custom/addXpController.ts new file mode 100644 index 00000000..d624388e --- /dev/null +++ b/src/controllers/custom/addXpController.ts @@ -0,0 +1,20 @@ +import { addGearExpByCategory, getInventory } from "@/src/services/inventoryService"; +import { getAccountIdForRequest } from "@/src/services/loginService"; +import { IEquipmentClient } from "@/src/types/inventoryTypes/commonInventoryTypes"; +import { TEquipmentKey } from "@/src/types/inventoryTypes/inventoryTypes"; +import { RequestHandler } from "express"; + +export const addXpController: RequestHandler = async (req, res) => { + const accountId = await getAccountIdForRequest(req); + const inventory = await getInventory(accountId); + const request = req.body as IAddXpRequest; + for (const [category, gear] of Object.entries(request)) { + addGearExpByCategory(inventory, gear, category as TEquipmentKey); + } + await inventory.save(); + res.end(); +}; + +type IAddXpRequest = { + [_ in TEquipmentKey]: IEquipmentClient[]; +}; diff --git a/src/routes/custom.ts b/src/routes/custom.ts index 3772362c..ad11383e 100644 --- a/src/routes/custom.ts +++ b/src/routes/custom.ts @@ -9,6 +9,7 @@ import { renameAccountController } from "@/src/controllers/custom/renameAccountC import { createAccountController } from "@/src/controllers/custom/createAccountController"; import { addItemsController } from "@/src/controllers/custom/addItemsController"; +import { addXpController } from "@/src/controllers/custom/addXpController"; import { importController } from "@/src/controllers/custom/importController"; import { getConfigDataController } from "@/src/controllers/custom/getConfigDataController"; @@ -25,6 +26,7 @@ customRouter.get("/renameAccount", renameAccountController); customRouter.post("/createAccount", createAccountController); customRouter.post("/addItems", addItemsController); +customRouter.post("/addXp", addXpController); customRouter.post("/import", importController); customRouter.get("/config", getConfigDataController); diff --git a/static/webui/script.js b/static/webui/script.js index c41688b2..56a9ce98 100644 --- a/static/webui/script.js +++ b/static/webui/script.js @@ -249,10 +249,7 @@ function updateInventory() { maxXP /= 2; } - if ( - item.XP < maxXP && - category != "MechSuits" // missionInventoryUpdate currently doesn't handle this category - ) { + if (item.XP < maxXP) { const a = document.createElement("a"); a.href = "#"; a.onclick = function (event) { @@ -645,8 +642,8 @@ function addGearExp(category, oid, xp) { ]; revalidateAuthz(() => { $.post({ - url: "/api/missionInventoryUpdate.php?" + window.authz, - contentType: "text/plain", + url: "/custom/addXp?" + window.authz, + contentType: "application/json", data: JSON.stringify(data) }).done(function () { if (category != "SpecialItems") { @@ -659,8 +656,8 @@ function addGearExp(category, oid, xp) { function sendBatchGearExp(data) { revalidateAuthz(() => { $.post({ - url: "/api/missionInventoryUpdate.php?" + window.authz, - contentType: "text/plain", + url: "/custom/addXp?" + window.authz, + contentType: "application/json", data: JSON.stringify(data) }).done(() => { updateInventory(); -- 2.47.2 From 989f8eda4b57ca65eef7398e63beed51872d403d Mon Sep 17 00:00:00 2001 From: Ordis <134585663+OrdisPrime@users.noreply.github.com> Date: Fri, 24 Jan 2025 16:03:44 +0100 Subject: [PATCH 2/4] adjust mission update controller --- .../api/missionInventoryUpdateController.ts | 20 ++++++++----------- src/services/missionInventoryUpdateService.ts | 9 ++------- src/utils/ts-utils.ts | 5 +++++ 3 files changed, 15 insertions(+), 19 deletions(-) create mode 100644 src/utils/ts-utils.ts diff --git a/src/controllers/api/missionInventoryUpdateController.ts b/src/controllers/api/missionInventoryUpdateController.ts index 9ae22eb9..1f9b6bbc 100644 --- a/src/controllers/api/missionInventoryUpdateController.ts +++ b/src/controllers/api/missionInventoryUpdateController.ts @@ -55,29 +55,25 @@ export const missionInventoryUpdateController: RequestHandler = async (req, res) const missionReport = getJSONfromString((req.body as string).toString()); - if (missionReport.MissionStatus !== "GS_SUCCESS") { - logger.debug(`Mission failed: ${missionReport.RewardInfo?.node}`); - //todo: return expected response for failed mission - res.json([]); - return; - //duvirisadjob does not provide missionStatus - } - const inventory = await getInventory(accountId); const missionRewardsResults = await addMissionRewards(inventory, missionReport); - if (!missionRewardsResults) { - logger.error("Failed to add mission rewards"); - res.status(500).json({ error: "Failed to add mission rewards" }); + if (missionReport.MissionStatus !== "GS_SUCCESS") { + const InventoryJson = JSON.stringify((await inventory.save()).toJSON()); + + res.json({ InventoryJson, MissionRewards: [] }); return; } + if (!missionRewardsResults) { + throw new Error("Failed to add mission rewards, should not happen"); + } + const { MissionRewards, inventoryChanges, missionCompletionCredits } = missionRewardsResults; const inventoryUpdates = addMissionInventoryUpdates(inventory, missionReport); - //todo ? can go after not awaiting //creditBonus is not correct for mirage mission 3 const credits = calculateFinalCredits(inventory, { missionCompletionCredits, diff --git a/src/services/missionInventoryUpdateService.ts b/src/services/missionInventoryUpdateService.ts index 1d6c5702..dc78d55a 100644 --- a/src/services/missionInventoryUpdateService.ts +++ b/src/services/missionInventoryUpdateService.ts @@ -21,6 +21,7 @@ import { HydratedDocument } from "mongoose"; import { IInventoryChanges } from "@/src/types/purchaseTypes"; import { getLevelKeyRewards, getNode } from "@/src/services/itemDataService"; import { InventoryDocumentProps, TInventoryDatabaseDocument } from "@/src/models/inventoryModels/inventoryModel"; +import { getEntriesUnsafe } from "@/src/utils/ts-utils"; const getRotations = (rotationCount: number): number[] => { if (rotationCount === 0) return [0]; @@ -64,12 +65,6 @@ export const fusionBundles: Record = { "/Lotus/Upgrades/Mods/FusionBundles/RareFusionBundle": 80 }; -type Entries = (K extends unknown ? [K, T[K]] : never)[]; - -function getEntriesUnsafe(object: T): Entries { - return Object.entries(object) as Entries; -} - //type TMissionInventoryUpdateKeys = keyof IMissionInventoryUpdateRequest; //const ignoredInventoryUpdateKeys = ["FpsAvg", "FpsMax", "FpsMin", "FpsSamples"] satisfies TMissionInventoryUpdateKeys[]; // for keys with no meaning for this server //type TignoredInventoryUpdateKeys = (typeof ignoredInventoryUpdateKeys)[number]; @@ -185,7 +180,7 @@ export const addMissionRewards = async ( { RewardInfo: rewardInfo, LevelKeyName: levelKeyName, Missions: missions }: IMissionInventoryUpdateRequest ) => { if (!rewardInfo) { - logger.error("no reward info provided"); + logger.warn("no reward info provided"); return; } diff --git a/src/utils/ts-utils.ts b/src/utils/ts-utils.ts new file mode 100644 index 00000000..4f456c12 --- /dev/null +++ b/src/utils/ts-utils.ts @@ -0,0 +1,5 @@ +type Entries = (K extends unknown ? [K, T[K]] : never)[]; + +export function getEntriesUnsafe(object: T): Entries { + return Object.entries(object) as Entries; +} -- 2.47.2 From 1750cac9d64aa3d1f981ff0fdb5dd4322d6aaee1 Mon Sep 17 00:00:00 2001 From: Ordis <134585663+OrdisPrime@users.noreply.github.com> Date: Fri, 24 Jan 2025 16:07:37 +0100 Subject: [PATCH 3/4] fix build --- src/controllers/api/missionInventoryUpdateController.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/api/missionInventoryUpdateController.ts b/src/controllers/api/missionInventoryUpdateController.ts index 1f9b6bbc..5d1e1d37 100644 --- a/src/controllers/api/missionInventoryUpdateController.ts +++ b/src/controllers/api/missionInventoryUpdateController.ts @@ -8,7 +8,7 @@ import { calculateFinalCredits } from "@/src/services/missionInventoryUpdateService"; import { getInventory } from "@/src/services/inventoryService"; -import { logger } from "@/src/utils/logger"; + /* **** INPUT **** - [ ] crossPlaySetting -- 2.47.2 From 6c9515a34d90c6732ed8812a071a1e0576e6e2aa Mon Sep 17 00:00:00 2001 From: Ordis <134585663+OrdisPrime@users.noreply.github.com> Date: Fri, 24 Jan 2025 16:15:41 +0100 Subject: [PATCH 4/4] dumdum --- src/controllers/api/missionInventoryUpdateController.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/controllers/api/missionInventoryUpdateController.ts b/src/controllers/api/missionInventoryUpdateController.ts index 5d1e1d37..837e449e 100644 --- a/src/controllers/api/missionInventoryUpdateController.ts +++ b/src/controllers/api/missionInventoryUpdateController.ts @@ -52,12 +52,10 @@ import { getInventory } from "@/src/services/inventoryService"; // eslint-disable-next-line @typescript-eslint/no-misused-promises export const missionInventoryUpdateController: RequestHandler = async (req, res): Promise => { const accountId = await getAccountIdForRequest(req); - const missionReport = getJSONfromString((req.body as string).toString()); const inventory = await getInventory(accountId); - - const missionRewardsResults = await addMissionRewards(inventory, missionReport); + const inventoryUpdates = addMissionInventoryUpdates(inventory, missionReport); if (missionReport.MissionStatus !== "GS_SUCCESS") { const InventoryJson = JSON.stringify((await inventory.save()).toJSON()); @@ -65,15 +63,12 @@ export const missionInventoryUpdateController: RequestHandler = async (req, res) res.json({ InventoryJson, MissionRewards: [] }); return; } - + const missionRewardsResults = await addMissionRewards(inventory, missionReport); if (!missionRewardsResults) { throw new Error("Failed to add mission rewards, should not happen"); } - const { MissionRewards, inventoryChanges, missionCompletionCredits } = missionRewardsResults; - const inventoryUpdates = addMissionInventoryUpdates(inventory, missionReport); - //creditBonus is not correct for mirage mission 3 const credits = calculateFinalCredits(inventory, { missionCompletionCredits, -- 2.47.2