返回提交历史
Modified
src/helpers/inventoryHelpers.ts
+6
-1
Modified
src/services/inventoryService.ts
+30
-0
XFEstudio/XFESpaceNinjaServer
fix: number parsing in convertFromLegacyFingerprint (#3645)
Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/3645 Reviewed-by: Sainan <63328889+sainan@users.noreply.github.com> Co-authored-by: AMelonInsideLemon <166175391+AMelonInsideLemon@users.noreply.github.com> Co-committed-by: AMelonInsideLemon <166175391+AMelonInsideLemon@users.noreply.github.com>
9c986076
代码差异
2 个文件
+36
-1
@@ -149,7 +149,12 @@ export const convertFromLegacyFingerprint = (s: string): string => {
149
149
const nextSep = s.indexOf("|", index);
150
150
const value = nextSep === -1 ? s.slice(index) : s.slice(index, nextSep);
151
151
index = nextSep === -1 ? s.length : nextSep;
152
obj[key] = value;
152
const num = Number(value);
153
if (!Number.isNaN(num)) {
154
obj[key] = num;
155
} else {
156
obj[key] = value;
157
}
153
158
}
154
159
155
160
return isArrayItem ? obj : obj;
@@ -70,6 +70,8 @@ import { createShip } from "./shipService.ts";
70
70
import type { TTraitsPool } from "../helpers/inventoryHelpers.ts";
71
71
import {
72
72
catbrowDetails,
73
convertFromLegacyFingerprint,
74
convertToLegacyFingerprint,
73
75
fromMongoDate,
74
76
fromOid,
75
77
kubrowDetails,
@@ -2756,6 +2758,34 @@ export const cleanupInventory = (inventory: TInventoryDatabaseDocument): void =>
2756
2758
}
2757
2759
}
2758
2760
2761
{
2762
let fixed = 0;
2763
for (const upgrade of inventory.Upgrades) {
2764
if (upgrade.UpgradeFingerprint) {
2765
const fingerprint = upgrade.UpgradeFingerprint;
2766
const json = JSON.parse(fingerprint) as {
2767
lvl?: number | string;
2768
lvlReq?: number | string;
2769
Progress?: number | string;
2770
reqLevel?: number | string;
2771
};
2772
2773
if (
2774
typeof json.lvl == "string" ||
2775
typeof json.lvlReq == "string" ||
2776
typeof json.Progress == "string" ||
2777
typeof json.reqLevel == "string"
2778
) {
2779
upgrade.UpgradeFingerprint = convertFromLegacyFingerprint(convertToLegacyFingerprint(fingerprint));
2780
++fixed;
2781
}
2782
}
2783
}
2784
if (fixed) {
2785
logger.debug(`fixed ${fixed} invalid upgrade fingerprints`);
2786
}
2787
}
2788
2759
2789
for (const pet of inventory.KubrowPets) {
2760
2790
if (!pet.Details) {
2761
2791
logger.debug(`removing invalid pet ${pet.ItemType} (${pet._id.toString()})`);