From 6ca887fc7b085b8630920b0c299067f836d9b63a Mon Sep 17 00:00:00 2001 From: Sainan Date: Fri, 7 Jun 2024 14:27:50 +0200 Subject: [PATCH 1/7] chore: update warframe-public-export-plus to 0.2.0 --- package-lock.json | 8 ++++---- package.json | 2 +- .../custom/getItemListsController.ts | 4 ++-- src/services/itemDataService.ts | 19 ++++++++++++++----- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/package-lock.json b/package-lock.json index efb09dce..46a8b08a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "express": "^5.0.0-beta.3", "mongoose": "^8.1.1", "warframe-items": "^1.1262.74", - "warframe-public-export-plus": "^0.1.0", + "warframe-public-export-plus": "^0.2.0", "warframe-riven-info": "^0.1.0", "winston": "^3.11.0", "winston-daily-rotate-file": "^4.7.1" @@ -3895,9 +3895,9 @@ } }, "node_modules/warframe-public-export-plus": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/warframe-public-export-plus/-/warframe-public-export-plus-0.1.0.tgz", - "integrity": "sha512-a76Be2pwPjKrin67zMux5L9U6zt9bhEtyy723tM2czGGcOZYWp1XdCZY684q3zPytWS0SmEia0C/h/4EiadBnQ==" + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/warframe-public-export-plus/-/warframe-public-export-plus-0.2.0.tgz", + "integrity": "sha512-JkTpkOzFWmjaK10H3CphGz4f6IAdH5higF9jyyTBbBD97U21C+3u9OGAoWav5CO8ydR2hLezcyOyRaqBAf4Abg==" }, "node_modules/warframe-riven-info": { "version": "0.1.0", diff --git a/package.json b/package.json index 50b38ba7..adcec54a 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "express": "^5.0.0-beta.3", "mongoose": "^8.1.1", "warframe-items": "^1.1262.74", - "warframe-public-export-plus": "^0.1.0", + "warframe-public-export-plus": "^0.2.0", "warframe-riven-info": "^0.1.0", "winston": "^3.11.0", "winston-daily-rotate-file": "^4.7.1" diff --git a/src/controllers/custom/getItemListsController.ts b/src/controllers/custom/getItemListsController.ts index 2efde908..ac987565 100644 --- a/src/controllers/custom/getItemListsController.ts +++ b/src/controllers/custom/getItemListsController.ts @@ -21,9 +21,9 @@ function reduceItems(items: MinItem[]): ListedItem[] { const getItemListsController: RequestHandler = (_req, res) => { const mods = reduceItems(items.filter(item => item.category == "Mods")); - for (const arcane of ExportArcanes) { + for (const [uniqueName, arcane] of Object.entries(ExportArcanes)) { mods.push({ - uniqueName: arcane.uniqueName, + uniqueName: uniqueName, name: getEnglishString(arcane.name) }); } diff --git a/src/services/itemDataService.ts b/src/services/itemDataService.ts index 0b33302c..55ebf31c 100644 --- a/src/services/itemDataService.ts +++ b/src/services/itemDataService.ts @@ -3,7 +3,7 @@ import { logger } from "@/src/utils/logger"; import Items, { Buildable, Category, MinimalItem, Warframe, Weapon } from "warframe-items"; import badItems from "@/static/json/exclude-mods.json"; import dict_en from "@/node_modules/warframe-public-export-plus/dict.en.json"; -import exportSuits from "@/node_modules/warframe-public-export-plus/ExportWarframes.json"; +import ExportWarframes from "@/node_modules/warframe-public-export-plus/ExportWarframes.json"; export type MinWarframe = Omit; export type MinWeapon = Omit; @@ -136,9 +136,18 @@ export const getItemCategoryByUniqueName = (uniqueName: string) => { return category; }; +namespace PublicExportPlus { + export interface IGenericExport { + [key: string]: any; + } + + export interface IDict { + [key: string]: string | undefined; + } +} + export const getSuitByUniqueName = (uniqueName: string) => { - const suit = exportSuits.find(suit => suit.uniqueName === uniqueName); - return suit; + return (ExportWarframes as PublicExportPlus.IGenericExport)[uniqueName]; }; export const getItemByUniqueName = (uniqueName: string) => { @@ -151,6 +160,6 @@ export const getItemByName = (name: string) => { return item; }; -export const getEnglishString = (key: string) => { - return dict_en[key as keyof typeof dict_en] ?? key; +export const getEnglishString = (key: string): string => { + return (dict_en as PublicExportPlus.IDict)[key] ?? key; }; -- 2.47.2 From cbcb845c416e67c4393edec8c8b15a1725321d2f Mon Sep 17 00:00:00 2001 From: Sainan Date: Fri, 7 Jun 2024 14:27:55 +0200 Subject: [PATCH 2/7] fix: being unable to add Grimoire --- .../custom/getItemListsController.ts | 15 +++++++++++++-- src/helpers/customHelpers/addItemHelpers.ts | 7 +------ src/services/itemDataService.ts | 17 +++++++++-------- static/webui/script.js | 3 +-- 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/controllers/custom/getItemListsController.ts b/src/controllers/custom/getItemListsController.ts index ac987565..bbcd8b06 100644 --- a/src/controllers/custom/getItemListsController.ts +++ b/src/controllers/custom/getItemListsController.ts @@ -1,7 +1,8 @@ import { RequestHandler } from "express"; -import { MinItem, MinWeapon, warframes, weapons, items, getEnglishString } from "@/src/services/itemDataService"; +import { MinItem, MinWeapon, warframes, items, getEnglishString } from "@/src/services/itemDataService"; import badItems from "@/static/json/exclude-mods.json"; import ExportArcanes from "@/node_modules/warframe-public-export-plus/ExportArcanes.json"; +import ExportWeapons from "@/node_modules/warframe-public-export-plus/ExportWeapons.json"; interface ListedItem { uniqueName: string; @@ -29,7 +30,17 @@ const getItemListsController: RequestHandler = (_req, res) => { } res.json({ warframes: reduceItems(warframes), - weapons: reduceItems(weapons.filter(item => item.productCategory != "OperatorAmps" && item.totalDamage != 0)), + weapons: Object.entries(ExportWeapons) + .filter( + ([_uniqueName, weapon]: [string, any]) => + weapon.productCategory !== "OperatorAmps" && weapon.totalDamage !== 0 + ) + .map(([uniqueName, weapon]: [string, any]) => { + return { + uniqueName, + name: getEnglishString(weapon.name) + }; + }), miscitems: reduceItems( items.filter( item => diff --git a/src/helpers/customHelpers/addItemHelpers.ts b/src/helpers/customHelpers/addItemHelpers.ts index 2b1f464d..5ce2378f 100644 --- a/src/helpers/customHelpers/addItemHelpers.ts +++ b/src/helpers/customHelpers/addItemHelpers.ts @@ -1,5 +1,4 @@ import { isString } from "@/src/helpers/general"; -import { items } from "@/src/services/itemDataService"; export enum ItemType { Powersuit = "Powersuit", @@ -22,13 +21,9 @@ interface IAddItemRequest { type: ItemType; InternalName: string; } -export const isInternalItemName = (internalName: string): boolean => { - const item = items.find(i => i.uniqueName === internalName); - return Boolean(item); -}; const parseInternalItemName = (internalName: unknown): string => { - if (!isString(internalName) || !isInternalItemName(internalName)) { + if (!isString(internalName)) { throw new Error("incorrect internal name"); } diff --git a/src/services/itemDataService.ts b/src/services/itemDataService.ts index 55ebf31c..5b78bff1 100644 --- a/src/services/itemDataService.ts +++ b/src/services/itemDataService.ts @@ -4,6 +4,7 @@ import Items, { Buildable, Category, MinimalItem, Warframe, Weapon } from "warfr import badItems from "@/static/json/exclude-mods.json"; import dict_en from "@/node_modules/warframe-public-export-plus/dict.en.json"; import ExportWarframes from "@/node_modules/warframe-public-export-plus/ExportWarframes.json"; +import ExportWeapons from "@/node_modules/warframe-public-export-plus/ExportWeapons.json"; export type MinWarframe = Omit; export type MinWeapon = Omit; @@ -19,13 +20,13 @@ export const warframes: MinWarframe[] = Array.from(new Items({ category: ["Warfr return next; }); -export const weapons: MinWeapon[] = Array.from( - new Items({ category: ["Primary", "Secondary", "Melee"] }) as Weapon[] -).map(item => { - const next = { ...item }; - delete next.patchlogs; - return next; -}); +const weapons: MinWeapon[] = Array.from(new Items({ category: ["Primary", "Secondary", "Melee"] }) as Weapon[]).map( + item => { + const next = { ...item }; + delete next.patchlogs; + return next; + } +); export type WeaponTypeInternal = "LongGuns" | "Pistols" | "Melee"; @@ -36,7 +37,7 @@ export const items: MinItem[] = Array.from(new Items({ category: ["All"] }) as M }); export const getWeaponType = (weaponName: string) => { - const weaponInfo = weapons.find(i => i.uniqueName === weaponName); + const weaponInfo = (ExportWeapons as PublicExportPlus.IGenericExport)[weaponName]; if (!weaponInfo) { throw new Error(`unknown weapon ${weaponName}`); diff --git a/static/webui/script.js b/static/webui/script.js index a50e0ab6..6d1e0a52 100644 --- a/static/webui/script.js +++ b/static/webui/script.js @@ -95,8 +95,7 @@ window.itemListPromise = new Promise(resolve => { "/Lotus/Weapons/Tenno/Rifle/LotusRifle": { name: "Rifle" }, "/Lotus/Weapons/Tenno/Shotgun/LotusShotgun": { name: "Shotgun" }, // Missing in data sources - "/Lotus/Upgrades/CosmeticEnhancers/Peculiars/CyoteMod": { name: "Traumatic Peculiar" }, - "/Lotus/Weapons/Tenno/Grimoire/TnGrimoire": { name: "Grimoire" } + "/Lotus/Upgrades/CosmeticEnhancers/Peculiars/CyoteMod": { name: "Traumatic Peculiar" } }; for (const [type, items] of Object.entries(data)) { if (type != "badItems") { -- 2.47.2 From 965bfaec6d9b04eecc8af50890f05440db694595 Mon Sep 17 00:00:00 2001 From: Sainan Date: Fri, 7 Jun 2024 16:20:36 +0200 Subject: [PATCH 3/7] improve: typings --- package-lock.json | 8 +++---- package.json | 2 +- .../custom/getItemListsController.ts | 7 +++--- src/services/itemDataService.ts | 24 +++++-------------- 4 files changed, 14 insertions(+), 27 deletions(-) diff --git a/package-lock.json b/package-lock.json index 46a8b08a..1fe81846 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "express": "^5.0.0-beta.3", "mongoose": "^8.1.1", "warframe-items": "^1.1262.74", - "warframe-public-export-plus": "^0.2.0", + "warframe-public-export-plus": "^0.2.2", "warframe-riven-info": "^0.1.0", "winston": "^3.11.0", "winston-daily-rotate-file": "^4.7.1" @@ -3895,9 +3895,9 @@ } }, "node_modules/warframe-public-export-plus": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/warframe-public-export-plus/-/warframe-public-export-plus-0.2.0.tgz", - "integrity": "sha512-JkTpkOzFWmjaK10H3CphGz4f6IAdH5higF9jyyTBbBD97U21C+3u9OGAoWav5CO8ydR2hLezcyOyRaqBAf4Abg==" + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/warframe-public-export-plus/-/warframe-public-export-plus-0.2.2.tgz", + "integrity": "sha512-PAsiyiRDqXcsUwZTweihwrSksd+GT3USrbHwS/TrJUC3TqLS0Ng24OfefFKPWOmPfMxDbdkg2zV39uq72iZ/Yg==" }, "node_modules/warframe-riven-info": { "version": "0.1.0", diff --git a/package.json b/package.json index adcec54a..88a71412 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "express": "^5.0.0-beta.3", "mongoose": "^8.1.1", "warframe-items": "^1.1262.74", - "warframe-public-export-plus": "^0.2.0", + "warframe-public-export-plus": "^0.2.2", "warframe-riven-info": "^0.1.0", "winston": "^3.11.0", "winston-daily-rotate-file": "^4.7.1" diff --git a/src/controllers/custom/getItemListsController.ts b/src/controllers/custom/getItemListsController.ts index bbcd8b06..dc4ba69c 100644 --- a/src/controllers/custom/getItemListsController.ts +++ b/src/controllers/custom/getItemListsController.ts @@ -1,8 +1,7 @@ import { RequestHandler } from "express"; import { MinItem, MinWeapon, warframes, items, getEnglishString } from "@/src/services/itemDataService"; import badItems from "@/static/json/exclude-mods.json"; -import ExportArcanes from "@/node_modules/warframe-public-export-plus/ExportArcanes.json"; -import ExportWeapons from "@/node_modules/warframe-public-export-plus/ExportWeapons.json"; +import { ExportArcanes, ExportWeapons } from "warframe-public-export-plus"; interface ListedItem { uniqueName: string; @@ -32,10 +31,10 @@ const getItemListsController: RequestHandler = (_req, res) => { warframes: reduceItems(warframes), weapons: Object.entries(ExportWeapons) .filter( - ([_uniqueName, weapon]: [string, any]) => + ([_uniqueName, weapon]) => weapon.productCategory !== "OperatorAmps" && weapon.totalDamage !== 0 ) - .map(([uniqueName, weapon]: [string, any]) => { + .map(([uniqueName, weapon]) => { return { uniqueName, name: getEnglishString(weapon.name) diff --git a/src/services/itemDataService.ts b/src/services/itemDataService.ts index 5b78bff1..455c051b 100644 --- a/src/services/itemDataService.ts +++ b/src/services/itemDataService.ts @@ -2,9 +2,7 @@ import { getIndexAfter } from "@/src/helpers/stringHelpers"; import { logger } from "@/src/utils/logger"; import Items, { Buildable, Category, MinimalItem, Warframe, Weapon } from "warframe-items"; import badItems from "@/static/json/exclude-mods.json"; -import dict_en from "@/node_modules/warframe-public-export-plus/dict.en.json"; -import ExportWarframes from "@/node_modules/warframe-public-export-plus/ExportWarframes.json"; -import ExportWeapons from "@/node_modules/warframe-public-export-plus/ExportWeapons.json"; +import { dict_en, ExportWarframes, ExportWeapons, IPowersuit } from "warframe-public-export-plus"; export type MinWarframe = Omit; export type MinWeapon = Omit; @@ -36,8 +34,8 @@ export const items: MinItem[] = Array.from(new Items({ category: ["All"] }) as M return next; }); -export const getWeaponType = (weaponName: string) => { - const weaponInfo = (ExportWeapons as PublicExportPlus.IGenericExport)[weaponName]; +export const getWeaponType = (weaponName: string): WeaponTypeInternal => { + const weaponInfo = ExportWeapons[weaponName]; if (!weaponInfo) { throw new Error(`unknown weapon ${weaponName}`); @@ -137,18 +135,8 @@ export const getItemCategoryByUniqueName = (uniqueName: string) => { return category; }; -namespace PublicExportPlus { - export interface IGenericExport { - [key: string]: any; - } - - export interface IDict { - [key: string]: string | undefined; - } -} - -export const getSuitByUniqueName = (uniqueName: string) => { - return (ExportWarframes as PublicExportPlus.IGenericExport)[uniqueName]; +export const getSuitByUniqueName = (uniqueName: string): IPowersuit | undefined => { + return ExportWarframes[uniqueName]; }; export const getItemByUniqueName = (uniqueName: string) => { @@ -162,5 +150,5 @@ export const getItemByName = (name: string) => { }; export const getEnglishString = (key: string): string => { - return (dict_en as PublicExportPlus.IDict)[key] ?? key; + return dict_en[key] ?? key; }; -- 2.47.2 From cfbe99e2f68a191c301b7c0eaa4fc8b4d1661bee Mon Sep 17 00:00:00 2001 From: Sainan Date: Fri, 7 Jun 2024 14:22:05 +0000 Subject: [PATCH 4/7] Apply prettier changes --- src/controllers/custom/getItemListsController.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/controllers/custom/getItemListsController.ts b/src/controllers/custom/getItemListsController.ts index dc4ba69c..f10b450b 100644 --- a/src/controllers/custom/getItemListsController.ts +++ b/src/controllers/custom/getItemListsController.ts @@ -30,10 +30,7 @@ const getItemListsController: RequestHandler = (_req, res) => { res.json({ warframes: reduceItems(warframes), weapons: Object.entries(ExportWeapons) - .filter( - ([_uniqueName, weapon]) => - weapon.productCategory !== "OperatorAmps" && weapon.totalDamage !== 0 - ) + .filter(([_uniqueName, weapon]) => weapon.productCategory !== "OperatorAmps" && weapon.totalDamage !== 0) .map(([uniqueName, weapon]) => { return { uniqueName, -- 2.47.2 From 99469771d0ce88440c9dbae4f5747e3c7b296850 Mon Sep 17 00:00:00 2001 From: Sainan Date: Fri, 7 Jun 2024 16:23:38 +0200 Subject: [PATCH 5/7] Remove unused weapons --- src/services/itemDataService.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/services/itemDataService.ts b/src/services/itemDataService.ts index 455c051b..6fb3cbac 100644 --- a/src/services/itemDataService.ts +++ b/src/services/itemDataService.ts @@ -18,14 +18,6 @@ export const warframes: MinWarframe[] = Array.from(new Items({ category: ["Warfr return next; }); -const weapons: MinWeapon[] = Array.from(new Items({ category: ["Primary", "Secondary", "Melee"] }) as Weapon[]).map( - item => { - const next = { ...item }; - delete next.patchlogs; - return next; - } -); - export type WeaponTypeInternal = "LongGuns" | "Pistols" | "Melee"; export const items: MinItem[] = Array.from(new Items({ category: ["All"] }) as MinimalItem[]).map(item => { -- 2.47.2 From 6406f6d763777feefdb4101a11430711dd3a6968 Mon Sep 17 00:00:00 2001 From: Sainan Date: Fri, 7 Jun 2024 16:43:06 +0200 Subject: [PATCH 6/7] improve: type safety for WeaponTypeInternal --- src/services/itemDataService.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/services/itemDataService.ts b/src/services/itemDataService.ts index 6fb3cbac..207be787 100644 --- a/src/services/itemDataService.ts +++ b/src/services/itemDataService.ts @@ -18,7 +18,7 @@ export const warframes: MinWarframe[] = Array.from(new Items({ category: ["Warfr return next; }); -export type WeaponTypeInternal = "LongGuns" | "Pistols" | "Melee"; +export type WeaponTypeInternal = "LongGuns" | "Pistols" | "Melee" | "SpaceMelee" | "SpaceGuns" | "SentinelWeapons" | "OperatorAmps" | "SpecialItems"; export const items: MinItem[] = Array.from(new Items({ category: ["All"] }) as MinimalItem[]).map(item => { const next = { ...item }; @@ -38,7 +38,7 @@ export const getWeaponType = (weaponName: string): WeaponTypeInternal => { throw new Error(`${weaponName} doesn't quack like a weapon`); } - const weaponType = weaponInfo.productCategory as WeaponTypeInternal; + const weaponType = weaponInfo.productCategory; if (!weaponType) { logger.error(`unknown weapon category for item ${weaponName}`); -- 2.47.2 From 34e4aac212a42e23e06b8378f564065046854141 Mon Sep 17 00:00:00 2001 From: Sainan Date: Fri, 7 Jun 2024 14:43:41 +0000 Subject: [PATCH 7/7] Apply prettier changes --- src/services/itemDataService.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/services/itemDataService.ts b/src/services/itemDataService.ts index 207be787..46a785ba 100644 --- a/src/services/itemDataService.ts +++ b/src/services/itemDataService.ts @@ -18,7 +18,15 @@ export const warframes: MinWarframe[] = Array.from(new Items({ category: ["Warfr return next; }); -export type WeaponTypeInternal = "LongGuns" | "Pistols" | "Melee" | "SpaceMelee" | "SpaceGuns" | "SentinelWeapons" | "OperatorAmps" | "SpecialItems"; +export type WeaponTypeInternal = + | "LongGuns" + | "Pistols" + | "Melee" + | "SpaceMelee" + | "SpaceGuns" + | "SentinelWeapons" + | "OperatorAmps" + | "SpecialItems"; export const items: MinItem[] = Array.from(new Items({ category: ["All"] }) as MinimalItem[]).map(item => { const next = { ...item }; -- 2.47.2