mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 18:57:03 +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
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "blitzkrieg",
|
||||
"version": "1.3.1",
|
||||
"version": "1.3.2",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"type": "module",
|
||||
|
||||
@@ -64,7 +64,7 @@ export default {
|
||||
`https://api.wotblitz.${server}/wotb/tanks/stats/?application_id=${args['wargaming-application-id']}&account_id=${id}`,
|
||||
);
|
||||
const tanks = tankStats[id]
|
||||
.map((tankData) => tankopedia.data[tankData.tank_id])
|
||||
.map((tankData) => tankopedia[tankData.tank_id])
|
||||
.filter((tank) => tank?.tier === tier);
|
||||
|
||||
await interaction.editReply({
|
||||
|
||||
@@ -52,7 +52,7 @@ export default {
|
||||
const accountInfo = await getWargamingResponse<AccountInfo>(
|
||||
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`,
|
||||
);
|
||||
const tank = tankopedia.data[tankId as unknown as number];
|
||||
const tank = tankopedia[tankId as unknown as number];
|
||||
|
||||
if (tank) {
|
||||
const periodicStats = (await getPeriodicStats(id, Number(period)))
|
||||
|
||||
@@ -29,7 +29,7 @@ import resolveTankName from '../utilities/resolveTankName.js';
|
||||
|
||||
export default {
|
||||
inProduction: true,
|
||||
inDevelopment: false,
|
||||
inDevelopment: true,
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
@@ -71,7 +71,7 @@ export default {
|
||||
key={tankId}
|
||||
name={resolveTankName({
|
||||
tank_id: tankId as unknown as number,
|
||||
name: tankopedia.data[tankId as unknown as number].name,
|
||||
name: tankopedia[tankId as unknown as number].name,
|
||||
})}
|
||||
winrate={tankStats.wins / tankStats.battles}
|
||||
careerWinrate={career.wins / career.battles}
|
||||
@@ -83,7 +83,7 @@ export default {
|
||||
careerSurvival={career.survived_battles / career.battles}
|
||||
battles={tankStats.battles}
|
||||
careerBattles={career.battles}
|
||||
icon={tankopedia.data[tankId as unknown as number].images.normal}
|
||||
icon={tankopedia[tankId as unknown as number].images.normal}
|
||||
/>
|
||||
);
|
||||
},
|
||||
|
||||
@@ -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