fix(webui): properly handle renaming of pets #2204

Merged
Sainan merged 1 commits from pet-name-fix into main 2025-06-19 04:23:37 -07:00
2 changed files with 34 additions and 11 deletions
Showing only changes of commit 7f3336b443 - Show all commits

View File

@ -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<IRenamePetRequest>(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
});
};

View File

@ -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();
});
}
});
}