返回提交历史
Modified
src/controllers/api/renamePetController.ts
+9
-2
Modified
static/webui/script.js
+25
-9
XFEstudio/XFESpaceNinjaServer
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>
d78ca91d
代码差异
2 个文件
+34
-11
@@ -1,6 +1,7 @@
1
1
import { getJSONfromString } from "@/src/helpers/stringHelpers";
2
2
import { getInventory, updateCurrency } from "@/src/services/inventoryService";
3
3
import { getAccountIdForRequest } from "@/src/services/loginService";
4
import { IInventoryChanges } from "@/src/types/purchaseTypes";
4
5
import { RequestHandler } from "express";
5
6
6
7
export const renamePetController: RequestHandler = async (req, res) => {
@@ -8,12 +9,18 @@ export const renamePetController: RequestHandler = async (req, res) => {
8
9
const inventory = await getInventory(accountId, "KubrowPets PremiumCredits PremiumCreditsFree");
9
10
const data = getJSONfromString<IRenamePetRequest>(String(req.body));
10
11
const details = inventory.KubrowPets.id(data.petId)!.Details!;
12
11
13
details.Name = data.name;
12
const currencyChanges = updateCurrency(inventory, 15, true);
14
15
const inventoryChanges: IInventoryChanges = {};
16
if (!("webui" in req.query)) {
17
updateCurrency(inventory, 15, true, inventoryChanges);
18
}
19
13
20
await inventory.save();
14
21
res.json({
15
22
...data,
16
inventoryChanges: currencyChanges
23
inventoryChanges: inventoryChanges
17
24
});
18
25
};
19
26
@@ -546,6 +546,9 @@ function updateInventory() {
546
546
td.textContent = item.ItemName + " (" + td.textContent + ")";
547
547
}
548
548
}
549
if (item.Details?.Name) {
550
td.textContent = item.Details.Name + " (" + td.textContent + ")";
551
}
549
552
if (item.ModularParts && item.ModularParts.length) {
550
553
td.textContent += " [";
551
554
item.ModularParts.forEach(part => {
@@ -1506,15 +1509,28 @@ function sendBatchGearExp(data) {
1506
1509
1507
1510
function renameGear(category, oid, name) {
1508
1511
revalidateAuthz(() => {
1509
$.post({
1510
url: "/api/nameWeapon.php?" + window.authz + "&Category=" + category + "&ItemId=" + oid + "&webui=1",
1511
contentType: "text/plain",
1512
data: JSON.stringify({
1513
ItemName: name
1514
})
1515
}).done(function () {
1516
updateInventory();
1517
});
1512
if (category == "KubrowPets") {
1513
$.post({
1514
url: "/api/renamePet.php?" + window.authz + "&webui=1",
1515
contentType: "text/plain",
1516
data: JSON.stringify({
1517
petId: oid,
1518
name: name
1519
})
1520
}).done(function () {
1521
updateInventory();
1522
});
1523
} else {
1524
$.post({
1525
url: "/api/nameWeapon.php?" + window.authz + "&Category=" + category + "&ItemId=" + oid + "&webui=1",
1526
contentType: "text/plain",
1527
data: JSON.stringify({
1528
ItemName: name
1529
})
1530
}).done(function () {
1531
updateInventory();
1532
});
1533
}
1518
1534
});
1519
1535
}
1520
1536