mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 03:59:50 +02:00
feat: cache images
This commit is contained in:
1 parent
c4044fb776
commit
d62708c21e
5 files changed
+32
-12
No files matched your search
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "blitzkrieg",
|
"name": "blitzkrieg",
|
||||||
"version": "1.3.1",
|
"version": "1.3.2",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ export default {
|
|||||||
`https://api.wotblitz.${server}/wotb/tanks/stats/?application_id=${args['wargaming-application-id']}&account_id=${id}`,
|
`https://api.wotblitz.${server}/wotb/tanks/stats/?application_id=${args['wargaming-application-id']}&account_id=${id}`,
|
||||||
);
|
);
|
||||||
const tanks = tankStats[id]
|
const tanks = tankStats[id]
|
||||||
.map((tankData) => tankopedia.data[tankData.tank_id])
|
.map((tankData) => tankopedia[tankData.tank_id])
|
||||||
.filter((tank) => tank?.tier === tier);
|
.filter((tank) => tank?.tier === tier);
|
||||||
|
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ export default {
|
|||||||
const accountInfo = await getWargamingResponse<AccountInfo>(
|
const accountInfo = await getWargamingResponse<AccountInfo>(
|
||||||
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`,
|
`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) {
|
if (tank) {
|
||||||
const periodicStats = (await getPeriodicStats(id, Number(period)))
|
const periodicStats = (await getPeriodicStats(id, Number(period)))
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ import resolveTankName from '../utilities/resolveTankName.js';
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
inProduction: true,
|
inProduction: true,
|
||||||
inDevelopment: false,
|
inDevelopment: true,
|
||||||
inPublic: true,
|
inPublic: true,
|
||||||
|
|
||||||
command: new SlashCommandBuilder()
|
command: new SlashCommandBuilder()
|
||||||
@@ -71,7 +71,7 @@ export default {
|
|||||||
key={tankId}
|
key={tankId}
|
||||||
name={resolveTankName({
|
name={resolveTankName({
|
||||||
tank_id: tankId as unknown as number,
|
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}
|
winrate={tankStats.wins / tankStats.battles}
|
||||||
careerWinrate={career.wins / career.battles}
|
careerWinrate={career.wins / career.battles}
|
||||||
@@ -83,7 +83,7 @@ export default {
|
|||||||
careerSurvival={career.survived_battles / career.battles}
|
careerSurvival={career.survived_battles / career.battles}
|
||||||
battles={tankStats.battles}
|
battles={tankStats.battles}
|
||||||
careerBattles={career.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: {
|
images: {
|
||||||
preview: string;
|
preview: string;
|
||||||
normal: string;
|
normal?: string;
|
||||||
};
|
};
|
||||||
tank_id: number;
|
tank_id: number;
|
||||||
type: TankType;
|
type: TankType;
|
||||||
@@ -26,15 +26,19 @@ export interface Tankopedia {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export const tankopedia = (await (
|
console.log('Caching tankopedia...');
|
||||||
|
export const tankopedia = (
|
||||||
|
(await (
|
||||||
await fetch('https://www.blitzstars.com/bs-tankopedia.json')
|
await fetch('https://www.blitzstars.com/bs-tankopedia.json')
|
||||||
).json()) as Tankopedia;
|
).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> = {
|
export const TANK_TYPE_NAMES: Record<TankType, string> = {
|
||||||
'AT-SPG': 'Tank Destroyer',
|
'AT-SPG': 'Tank Destroyer',
|
||||||
@@ -49,3 +53,19 @@ export const TANK_TYPE_EMOJIS: Record<TankType, string> = {
|
|||||||
mediumTank: '🇲',
|
mediumTank: '🇲',
|
||||||
lightTank: '🇱',
|
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