返回提交历史
Modified
static/webui/script.js
+137
-124
XFEstudio/XFESpaceNinjaServer
fix(webui): ensure that all requests using authz revalidate it (#1911)
Closes #1907 Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/1911 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
de1e2a25
代码差异
1 个文件
+137
-124
@@ -375,6 +375,7 @@ function fetchItemList() {
375
375
}
376
376
fetchItemList();
377
377
378
// Assumes that caller revalidates authz
378
379
function updateInventory() {
379
380
const req = $.get("/api/inventory.php?" + window.authz + "&xpBasedLevelCapDisabled=1");
380
381
req.done(data => {
@@ -487,25 +488,27 @@ function updateInventory() {
487
488
a.href = "#";
488
489
a.onclick = function (event) {
489
490
event.preventDefault();
490
if (item.XP < maxXP) {
491
addGearExp(category, item.ItemId.$oid, maxXP - item.XP);
492
}
493
if ("exalted" in itemMap[item.ItemType]) {
494
for (const exaltedType of itemMap[item.ItemType].exalted) {
495
const exaltedItem = data.SpecialItems.find(x => x.ItemType == exaltedType);
496
if (exaltedItem) {
497
const exaltedCap =
498
itemMap[exaltedType]?.type == "weapons" ? 800_000 : 1_600_000;
499
if (exaltedItem.XP < exaltedCap) {
500
addGearExp(
501
"SpecialItems",
502
exaltedItem.ItemId.$oid,
503
exaltedCap - exaltedItem.XP
504
);
491
revalidateAuthz(() => {
492
if (item.XP < maxXP) {
493
addGearExp(category, item.ItemId.$oid, maxXP - item.XP);
494
}
495
if ("exalted" in itemMap[item.ItemType]) {
496
for (const exaltedType of itemMap[item.ItemType].exalted) {
497
const exaltedItem = data.SpecialItems.find(x => x.ItemType == exaltedType);
498
if (exaltedItem) {
499
const exaltedCap =
500
itemMap[exaltedType]?.type == "weapons" ? 800_000 : 1_600_000;
501
if (exaltedItem.XP < exaltedCap) {
502
addGearExp(
503
"SpecialItems",
504
exaltedItem.ItemId.$oid,
505
exaltedCap - exaltedItem.XP
506
);
507
}
505
508
}
506
509
}
507
510
}
508
}
511
});
509
512
};
510
513
a.title = loc("code_maxRank");
511
514
a.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M214.6 41.4c-12.5-12.5-32.8-12.5-45.3 0l-160 160c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L160 141.2V448c0 17.7 14.3 32 32 32s32-14.3 32-32V141.2L329.4 246.6c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3l-160-160z"/></svg>`;
@@ -1229,83 +1232,87 @@ function addMissingEvolutionProgress() {
1229
1232
}
1230
1233
1231
1234
function maxRankAllEvolutions() {
1232
const req = $.get("/api/inventory.php?" + window.authz + "&xpBasedLevelCapDisabled=1");
1235
revalidateAuthz(() => {
1236
const req = $.get("/api/inventory.php?" + window.authz + "&xpBasedLevelCapDisabled=1");
1237
req.done(data => {
1238
const requests = [];
1233
1239
1234
req.done(data => {
1235
const requests = [];
1240
data.EvolutionProgress.forEach(item => {
1241
if (item.Rank < 5) {
1242
requests.push({
1243
ItemType: item.ItemType,
1244
Rank: 5
1245
});
1246
}
1247
});
1236
1248
1237
data.EvolutionProgress.forEach(item => {
1238
if (item.Rank < 5) {
1239
requests.push({
1240
ItemType: item.ItemType,
1241
Rank: 5
1242
});
1249
if (Object.keys(requests).length > 0) {
1250
return setEvolutionProgress(requests);
1243
1251
}
1244
});
1245
1246
if (Object.keys(requests).length > 0) {
1247
return setEvolutionProgress(requests);
1248
}
1249
1252
1250
toast(loc("code_noEquipmentToRankUp"));
1253
toast(loc("code_noEquipmentToRankUp"));
1254
});
1251
1255
});
1252
1256
}
1253
1257
1254
1258
function maxRankAllEquipment(categories) {
1255
const req = $.get("/api/inventory.php?" + window.authz + "&xpBasedLevelCapDisabled=1");
1256
1257
req.done(data => {
1258
window.itemListPromise.then(itemMap => {
1259
const batchData = {};
1260
1261
categories.forEach(category => {
1262
data[category].forEach(item => {
1263
const maxXP =
1264
category === "Suits" ||
1265
category === "SpaceSuits" ||
1266
category === "Sentinels" ||
1267
category === "Hoverboards"
1268
? 1_600_000
1269
: 800_000;
1270
1271
if (item.XP < maxXP) {
1272
if (!batchData[category]) {
1273
batchData[category] = [];
1259
revalidateAuthz(() => {
1260
const req = $.get("/api/inventory.php?" + window.authz + "&xpBasedLevelCapDisabled=1");
1261
req.done(data => {
1262
window.itemListPromise.then(itemMap => {
1263
const batchData = {};
1264
1265
categories.forEach(category => {
1266
data[category].forEach(item => {
1267
const maxXP =
1268
category === "Suits" ||
1269
category === "SpaceSuits" ||
1270
category === "Sentinels" ||
1271
category === "Hoverboards"
1272
? 1_600_000
1273
: 800_000;
1274
1275
if (item.XP < maxXP) {
1276
if (!batchData[category]) {
1277
batchData[category] = [];
1278
}
1279
batchData[category].push({
1280
ItemId: { $oid: item.ItemId.$oid },
1281
XP: maxXP
1282
});
1274
1283
}
1275
batchData[category].push({
1276
ItemId: { $oid: item.ItemId.$oid },
1277
XP: maxXP
1278
});
1279
}
1280
if (category === "Suits") {
1281
if ("exalted" in itemMap[item.ItemType]) {
1282
for (const exaltedType of itemMap[item.ItemType].exalted) {
1283
const exaltedItem = data["SpecialItems"].find(x => x.ItemType == exaltedType);
1284
if (exaltedItem) {
1285
const exaltedCap = itemMap[exaltedType]?.type == "weapons" ? 800_000 : 1_600_000;
1286
if (exaltedItem.XP < exaltedCap) {
1287
batchData["SpecialItems"] ??= [];
1288
batchData["SpecialItems"].push({
1289
ItemId: { $oid: exaltedItem.ItemId.$oid },
1290
XP: exaltedCap
1291
});
1284
if (category === "Suits") {
1285
if ("exalted" in itemMap[item.ItemType]) {
1286
for (const exaltedType of itemMap[item.ItemType].exalted) {
1287
const exaltedItem = data["SpecialItems"].find(x => x.ItemType == exaltedType);
1288
if (exaltedItem) {
1289
const exaltedCap =
1290
itemMap[exaltedType]?.type == "weapons" ? 800_000 : 1_600_000;
1291
if (exaltedItem.XP < exaltedCap) {
1292
batchData["SpecialItems"] ??= [];
1293
batchData["SpecialItems"].push({
1294
ItemId: { $oid: exaltedItem.ItemId.$oid },
1295
XP: exaltedCap
1296
});
1297
}
1292
1298
}
1293
1299
}
1294
1300
}
1295
1301
}
1296
}
1302
});
1297
1303
});
1298
});
1299
1304
1300
if (Object.keys(batchData).length > 0) {
1301
return sendBatchGearExp(batchData);
1302
}
1305
if (Object.keys(batchData).length > 0) {
1306
return sendBatchGearExp(batchData);
1307
}
1303
1308
1304
toast(loc("code_noEquipmentToRankUp"));
1309
toast(loc("code_noEquipmentToRankUp"));
1310
});
1305
1311
});
1306
1312
});
1307
1313
}
1308
1314
1315
// Assumes that caller revalidates authz
1309
1316
function addGearExp(category, oid, xp) {
1310
1317
const data = {};
1311
1318
data[category] = [
@@ -1314,16 +1321,14 @@ function addGearExp(category, oid, xp) {
1314
1321
XP: xp
1315
1322
}
1316
1323
];
1317
revalidateAuthz(() => {
1318
$.post({
1319
url: "/custom/addXp?" + window.authz,
1320
contentType: "application/json",
1321
data: JSON.stringify(data)
1322
}).done(function () {
1323
if (category != "SpecialItems") {
1324
updateInventory();
1325
}
1326
});
1324
$.post({
1325
url: "/custom/addXp?" + window.authz,
1326
contentType: "application/json",
1327
data: JSON.stringify(data)
1328
}).done(function () {
1329
if (category != "SpecialItems") {
1330
updateInventory();
1331
}
1327
1332
});
1328
1333
}
1329
1334
@@ -1598,32 +1603,34 @@ function doAcquireMod() {
1598
1603
const uiConfigs = [...$("#server-settings input[id]")].map(x => x.id);
1599
1604
1600
1605
function doChangeSettings() {
1601
fetch("/custom/config?" + window.authz)
1602
.then(response => response.json())
1603
.then(json => {
1604
for (const i of uiConfigs) {
1605
var x = document.getElementById(i);
1606
if (x != null) {
1607
if (x.type == "checkbox") {
1608
if (x.checked === true) {
1609
json[i] = true;
1610
} else {
1611
json[i] = false;
1606
revalidateAuthz(() => {
1607
fetch("/custom/config?" + window.authz)
1608
.then(response => response.json())
1609
.then(json => {
1610
for (const i of uiConfigs) {
1611
var x = document.getElementById(i);
1612
if (x != null) {
1613
if (x.type == "checkbox") {
1614
if (x.checked === true) {
1615
json[i] = true;
1616
} else {
1617
json[i] = false;
1618
}
1619
} else if (x.type == "number") {
1620
json[i] = parseInt(x.value);
1612
1621
}
1613
} else if (x.type == "number") {
1614
json[i] = parseInt(x.value);
1615
1622
}
1616
1623
}
1617
}
1618
$.post({
1619
url: "/custom/config?" + window.authz,
1620
contentType: "text/plain",
1621
data: JSON.stringify(json, null, 2)
1622
}).then(() => {
1623
// A few cheats affect the inventory response which in turn may change what values we need to show
1624
updateInventory();
1624
$.post({
1625
url: "/custom/config?" + window.authz,
1626
contentType: "text/plain",
1627
data: JSON.stringify(json, null, 2)
1628
}).then(() => {
1629
// A few cheats affect the inventory response which in turn may change what values we need to show
1630
updateInventory();
1631
});
1625
1632
});
1626
});
1633
});
1627
1634
}
1628
1635
1629
1636
// Cheats route
@@ -1876,33 +1883,39 @@ function doChangeSupportedSyndicate() {
1876
1883
}
1877
1884
1878
1885
function doAddCurrency(currency) {
1879
$.post({
1880
url: "/custom/addCurrency?" + window.authz,
1881
contentType: "application/json",
1882
data: JSON.stringify({
1883
currency,
1884
delta: document.getElementById(currency + "-delta").valueAsNumber
1885
})
1886
}).then(function () {
1887
updateInventory();
1886
revalidateAuthz(() => {
1887
$.post({
1888
url: "/custom/addCurrency?" + window.authz,
1889
contentType: "application/json",
1890
data: JSON.stringify({
1891
currency,
1892
delta: document.getElementById(currency + "-delta").valueAsNumber
1893
})
1894
}).then(function () {
1895
updateInventory();
1896
});
1888
1897
});
1889
1898
}
1890
1899
1891
1900
function doQuestUpdate(operation, itemType) {
1892
$.post({
1893
url: "/custom/manageQuests?" + window.authz + "&operation=" + operation + "&itemType=" + itemType,
1894
contentType: "application/json"
1895
}).then(function () {
1896
updateInventory();
1901
revalidateAuthz(() => {
1902
$.post({
1903
url: "/custom/manageQuests?" + window.authz + "&operation=" + operation + "&itemType=" + itemType,
1904
contentType: "application/json"
1905
}).then(function () {
1906
updateInventory();
1907
});
1897
1908
});
1898
1909
}
1899
1910
1900
1911
function doBulkQuestUpdate(operation) {
1901
$.post({
1902
url: "/custom/manageQuests?" + window.authz + "&operation=" + operation,
1903
contentType: "application/json"
1904
}).then(function () {
1905
updateInventory();
1912
revalidateAuthz(() => {
1913
$.post({
1914
url: "/custom/manageQuests?" + window.authz + "&operation=" + operation,
1915
contentType: "application/json"
1916
}).then(function () {
1917
updateInventory();
1918
});
1906
1919
});
1907
1920
}
1908
1921