mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 03:29:51 +02:00
feat: cache images
This commit is contained in:
1 parent
c4044fb776
commit
d62708c21e
5 files changed
+33
-13
No files matched your search
@@ -17,7 +17,7 @@ export interface Tankopedia {
|
||||
};
|
||||
images: {
|
||||
preview: string;
|
||||
normal: string;
|
||||
normal?: string;
|
||||
};
|
||||
tank_id: number;
|
||||
type: TankType;
|
||||
@@ -26,15 +26,19 @@ export interface Tankopedia {
|
||||
};
|
||||
}
|
||||
|
||||
export const tankopedia = (await (
|
||||
await fetch('https://www.blitzstars.com/bs-tankopedia.json')
|
||||
).json()) as Tankopedia;
|
||||
console.log('Caching tankopedia...');
|
||||
export const tankopedia = (
|
||||
(await (
|
||||
await fetch('https://www.blitzstars.com/bs-tankopedia.json')
|
||||
).json()) as Tankopedia
|
||||
).data;
|
||||
console.log('Cached tankopedia');
|
||||
|
||||
export const tankIds = Object.keys(tankopedia.data) as unknown as number[];
|
||||
export const tankIds = Object.keys(tankopedia) as unknown as number[];
|
||||
|
||||
export const tankNames = tankIds.map((id) => tankopedia.data[id].name);
|
||||
export const tankNames = tankIds.map((id) => tankopedia[id].name);
|
||||
|
||||
export const tanks = tankIds.map((id) => tankopedia.data[id]);
|
||||
export const tanks = tankIds.map((id) => tankopedia[id]);
|
||||
|
||||
export const TANK_TYPE_NAMES: Record<TankType, string> = {
|
||||
'AT-SPG': 'Tank Destroyer',
|
||||
@@ -49,3 +53,19 @@ export const TANK_TYPE_EMOJIS: Record<TankType, string> = {
|
||||
mediumTank: '🇲',
|
||||
lightTank: '🇱',
|
||||
};
|
||||
|
||||
console.log('Encoding tank images...');
|
||||
await Promise.all(
|
||||
Object.entries(tankopedia).map(async ([, tank]) => {
|
||||
if (tank.images.normal) {
|
||||
const response = await fetch(tank.images.normal);
|
||||
const blob = await response.arrayBuffer();
|
||||
const base64 = `data:${response.headers.get(
|
||||
'content-type',
|
||||
)};base64,${Buffer.from(blob).toString('base64')}`;
|
||||
|
||||
tank.images.normal = base64;
|
||||
}
|
||||
}),
|
||||
);
|
||||
console.log('Encoded tank images');
|
||||
Reference in new issue
Block a user