mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 10:47:04 +02:00
feat: cache tankopedia and tankaverages during build
This commit is contained in:
1 parent
79343438f0
commit
0f46f333b5
7 files changed
+59
-44
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import { WargamingResponse } from '../../types/wargamingResponse.js';
|
||||
import { readFileSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
|
||||
export type TankType = 'AT-SPG' | 'lightTank' | 'mediumTank' | 'heavyTank';
|
||||
|
||||
@@ -18,30 +19,15 @@ export interface Tankopedia {
|
||||
[id: number]: TankopediaEntry;
|
||||
}
|
||||
|
||||
export const tankopedia: Tankopedia = {};
|
||||
export const TANK_IDS: number[] = [];
|
||||
export const TANKS: TankopediaEntry[] = [];
|
||||
export const TANK_NAMES: string[] = [];
|
||||
|
||||
console.log('Caching tankopedia...');
|
||||
fetch('https://www.blitzstars.com/bs-tankopedia.json')
|
||||
.then(
|
||||
(response) =>
|
||||
response.json() as Promise<
|
||||
WargamingResponse<Tankopedia> & { status: 'ok' }
|
||||
>,
|
||||
)
|
||||
.then((wargamingResponse) => {
|
||||
Object.assign(tankopedia, wargamingResponse.data);
|
||||
Object.entries(tankopedia).forEach(([idString, entry]) => {
|
||||
const id = Number(idString);
|
||||
|
||||
TANK_IDS.push(id);
|
||||
TANKS.push(entry);
|
||||
TANK_NAMES.push(entry.name);
|
||||
}),
|
||||
console.log('Cached tankopedia');
|
||||
});
|
||||
export const tankopedia = (
|
||||
JSON.parse(
|
||||
readFileSync(join(__dirname, 'tankopedia.json')) as unknown as string,
|
||||
) 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);
|
||||
export const TANK_NAMES = entries.map(([, { name }]) => name);
|
||||
|
||||
export const TANK_ICONS: Record<TankType, string> = {
|
||||
'AT-SPG': 'https://i.imgur.com/BIHSEH0.png',
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { readFileSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
import { AllStats } from '../../types/accountInfo.js';
|
||||
|
||||
export interface SpecialStats {
|
||||
@@ -78,14 +80,8 @@ export interface IndividualTankAverage {
|
||||
last_update: number;
|
||||
}
|
||||
|
||||
export const tankAverages: Record<number, IndividualTankAverage> = {};
|
||||
export type TankAverages = Record<number, IndividualTankAverage>;
|
||||
|
||||
console.log('Caching tank averages...');
|
||||
fetch('https://www.blitzstars.com/api/tankaverages.json')
|
||||
.then((response) => response.json() as Promise<IndividualTankAverage[]>)
|
||||
.then((individualTankAverages) => {
|
||||
individualTankAverages.forEach((individualTankAverage) => {
|
||||
tankAverages[individualTankAverage.tank_id] = individualTankAverage;
|
||||
});
|
||||
console.log('Tank averages cached');
|
||||
});
|
||||
export const tankAverages = JSON.parse(
|
||||
readFileSync(join(__dirname, 'tankaverages.json')) as unknown as string,
|
||||
) as TankAverages;
|
||||
@@ -3,5 +3,3 @@ const isDevBoolean = process.env.NODE_ENV === 'development';
|
||||
export default function isDev() {
|
||||
return isDevBoolean;
|
||||
}
|
||||
|
||||
console.log(process.env.NODE_ENV);
|
||||
+1
-1
@@ -15,4 +15,4 @@ app.get('/', async (req, res) => {
|
||||
res.end(svg);
|
||||
});
|
||||
|
||||
app.listen(process.env.PORT || 3000);
|
||||
app.listen(process.env.PORT ?? 3000);
|
||||
Reference in new issue
Block a user