mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
feat: moved tankopedia and tankaverages into a runtime cache
This commit is contained in:
1 parent
95b105cb65
commit
00b721f34f
29 files changed
+268
-235
No files matched your search
@@ -2,7 +2,7 @@ import { go } from 'fuzzysort';
|
||||
import throwError from '../node/throwError.js';
|
||||
import { TANKS, tankopedia } from './tankopedia.js';
|
||||
|
||||
export default function resolveTankId(tank: string) {
|
||||
export default async function resolveTankId(tank: string) {
|
||||
const number = parseInt(tank);
|
||||
|
||||
if (Number.isNaN(number)) {
|
||||
@@ -17,7 +17,7 @@ export default function resolveTankId(tank: string) {
|
||||
return searchResult[0].obj.tank_id;
|
||||
}
|
||||
} else {
|
||||
if (tankopedia[number]) {
|
||||
if ((await tankopedia)[number]) {
|
||||
return number;
|
||||
} else {
|
||||
throw throwError(
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { tankopedia } from './tankopedia.js';
|
||||
|
||||
export default function resolveTankName(tankId: number) {
|
||||
const tankopediaName = tankopedia[tankId].name;
|
||||
export default async function resolveTankName(tankId: number) {
|
||||
const tankopediaName = (await tankopedia)[tankId].name;
|
||||
return tankopediaName ? tankopediaName : `Unknown Tank ${tankId}`;
|
||||
}
|
||||
@@ -1,6 +1,3 @@
|
||||
import { readFileSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
|
||||
export type TankType = 'AT-SPG' | 'lightTank' | 'mediumTank' | 'heavyTank';
|
||||
|
||||
export interface TankopediaEntry {
|
||||
@@ -19,11 +16,13 @@ export interface Tankopedia {
|
||||
[id: number]: TankopediaEntry;
|
||||
}
|
||||
|
||||
export const tankopedia = (
|
||||
JSON.parse(
|
||||
readFileSync(join(__dirname, 'tankopedia.json')) as unknown as string,
|
||||
) as { data: Tankopedia }
|
||||
).data;
|
||||
console.log('Caching tankopedia...');
|
||||
export const tankopedia = fetch('https://www.blitzstars.com/bs-tankopedia.json')
|
||||
.then((response) => response.json())
|
||||
.then((wrapperTankopedia) => {
|
||||
console.log('Tankopedia cached');
|
||||
return (wrapperTankopedia as { data: Tankopedia }).data;
|
||||
});
|
||||
const entries = Object.entries(tankopedia);
|
||||
export const TANK_IDS = entries.map(([, { tank_id }]) => tank_id as number);
|
||||
export const TANKS = entries.map(([, entry]) => entry as TankopediaEntry);
|
||||
|
||||
Reference in new issue
Block a user