From d78ca91d6c60c748f8d883b7d59c7f3d9b611072 Mon Sep 17 00:00:00 2001 From: Sainan <63328889+Sainan@users.noreply.github.com> Date: Thu, 19 Jun 2025 04:23:33 -0700 Subject: [PATCH] fix(webui): properly handle renaming of pets (#2204) Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/2204 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com> --- src/controllers/api/renamePetController.ts | 11 +++++-- static/webui/script.js | 34 ++++++++++++++++------ 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/src/controllers/api/renamePetController.ts b/src/controllers/api/renamePetController.ts index 6672d064..61212641 100644 --- a/src/controllers/api/renamePetController.ts +++ b/src/controllers/api/renamePetController.ts @@ -1,6 +1,7 @@ import { getJSONfromString } from "@/src/helpers/stringHelpers"; import { getInventory, updateCurrency } from "@/src/services/inventoryService"; import { getAccountIdForRequest } from "@/src/services/loginService"; +import { IInventoryChanges } from "@/src/types/purchaseTypes"; import { RequestHandler } from "express"; export const renamePetController: RequestHandler = async (req, res) => { @@ -8,12 +9,18 @@ export const renamePetController: RequestHandler = async (req, res) => { const inventory = await getInventory(accountId, "KubrowPets PremiumCredits PremiumCreditsFree"); const data = getJSONfromString(String(req.body)); const details = inventory.KubrowPets.id(data.petId)!.Details!; + details.Name = data.name; - const currencyChanges = updateCurrency(inventory, 15, true); + + const inventoryChanges: IInventoryChanges = {}; + if (!("webui" in req.query)) { + updateCurrency(inventory, 15, true, inventoryChanges); + } + await inventory.save(); res.json({ ...data, - inventoryChanges: currencyChanges + inventoryChanges: inventoryChanges }); }; diff --git a/static/webui/script.js b/static/webui/script.js index bb7ec52a..bd32266f 100644 --- a/static/webui/script.js +++ b/static/webui/script.js @@ -546,6 +546,9 @@ function updateInventory() { td.textContent = item.ItemName + " (" + td.textContent + ")"; } } + if (item.Details?.Name) { + td.textContent = item.Details.Name + " (" + td.textContent + ")"; + } if (item.ModularParts && item.ModularParts.length) { td.textContent += " ["; item.ModularParts.forEach(part => { @@ -1506,15 +1509,28 @@ function sendBatchGearExp(data) { function renameGear(category, oid, name) { revalidateAuthz(() => { - $.post({ - url: "/api/nameWeapon.php?" + window.authz + "&Category=" + category + "&ItemId=" + oid + "&webui=1", - contentType: "text/plain", - data: JSON.stringify({ - ItemName: name - }) - }).done(function () { - updateInventory(); - }); + if (category == "KubrowPets") { + $.post({ + url: "/api/renamePet.php?" + window.authz + "&webui=1", + contentType: "text/plain", + data: JSON.stringify({ + petId: oid, + name: name + }) + }).done(function () { + updateInventory(); + }); + } else { + $.post({ + url: "/api/nameWeapon.php?" + window.authz + "&Category=" + category + "&ItemId=" + oid + "&webui=1", + contentType: "text/plain", + data: JSON.stringify({ + ItemName: name + }) + }).done(function () { + updateInventory(); + }); + } }); }