feat: optimized tankopedia information

This commit is contained in:
TresAbhi committed 2023-07-08 19:47:21 +00:00
1 parent 57271e3c23
commit 2bf5eb78be
2 files changed
+13 -18

No files matched your search

+2 -2
View File
@@ -1,8 +1,8 @@
import { TANK_ICONS, TankType } from '../../../core/blitz/tankopedia.js'; import { TANK_ICONS } from '../../../core/blitz/tankopedia.js';
export interface ItemProps { export interface ItemProps {
icon?: string; icon?: string;
type?: TankType; type?: string;
name: string; name: string;
} }
+11 -16
View File
@@ -1,15 +1,13 @@
export type TankType = 'AT-SPG' | 'lightTank' | 'mediumTank' | 'heavyTank'; import { WARGAMING_APPLICATION_ID } from '../node/arguments.js';
import getWargamingResponse from './getWargamingResponse.js';
export interface TankopediaEntry { export interface TankopediaEntry {
name: string;
nation: string;
is_premium: boolean;
tier: number;
cost: { price_credit: number; price_gold: number };
images: { preview: string; normal: string };
tank_id: number; tank_id: number;
type: TankType; name: string;
description: string; tier: number;
type: string;
is_premium: boolean;
images: { preview: string; normal: string };
} }
export interface Tankopedia { export interface Tankopedia {
@@ -17,12 +15,9 @@ export interface Tankopedia {
} }
console.log('Caching tankopedia...'); console.log('Caching tankopedia...');
export const tankopedia = fetch('https://www.blitzstars.com/bs-tankopedia.json') export const tankopedia = getWargamingResponse<Tankopedia>(
.then((response) => response.json()) `https://api.wotblitz.com/wotb/encyclopedia/vehicles/?application_id=${WARGAMING_APPLICATION_ID}&fields=name,tier,images,tank_id,type,is_premium`,
.then((wrapperTankopedia) => { );
console.log('Tankopedia cached');
return (wrapperTankopedia as { data: Tankopedia }).data;
});
const entries = new Promise<TankopediaEntry[]>(async (resolve) => { const entries = new Promise<TankopediaEntry[]>(async (resolve) => {
resolve(Object.entries(await tankopedia).map(([, entry]) => entry)); resolve(Object.entries(await tankopedia).map(([, entry]) => entry));
}); });
@@ -33,7 +28,7 @@ export const TANK_NAMES = new Promise<string[]>(async (resolve) => {
resolve((await entries).map(({ name }) => name)); resolve((await entries).map(({ name }) => name));
}); });
export const TANK_ICONS: Record<TankType, string> = { export const TANK_ICONS: Record<string, string> = {
'AT-SPG': 'https://i.imgur.com/BIHSEH0.png', 'AT-SPG': 'https://i.imgur.com/BIHSEH0.png',
lightTank: 'https://i.imgur.com/CSNha5V.png', lightTank: 'https://i.imgur.com/CSNha5V.png',
mediumTank: 'https://i.imgur.com/wvf3ltm.png', mediumTank: 'https://i.imgur.com/wvf3ltm.png',