fix: skip encoding tanks without images

This commit is contained in:
TresAbhi committed 2023-06-03 18:25:33 +00:00
1 parent db881f44d4
commit 1d0b428921
14 files changed
+35 -56

No files matched your search

+1 -1
View File
@@ -13,7 +13,7 @@ const executionStart = new Date().getTime();
export default {
inProduction: true,
inDevelopment: true,
inDevelopment: false,
inPublic: true,
command: new SlashCommandBuilder()
+1 -1
View File
@@ -11,7 +11,7 @@ import { client } from '../index.js';
export default {
inProduction: true,
inDevelopment: true,
inDevelopment: false,
inPublic: true,
command: new SlashCommandBuilder()
+1 -1
View File
@@ -15,7 +15,7 @@ const DEFAULT_THRESHOLD = 7;
export default {
inProduction: true,
inDevelopment: true,
inDevelopment: false,
inPublic: true,
command: new SlashCommandBuilder()
+1 -1
View File
@@ -36,7 +36,7 @@ const COMP_TANKS = [
export default {
inProduction: true,
inDevelopment: true,
inDevelopment: false,
inPublic: true,
command: new SlashCommandBuilder()
+1 -1
View File
@@ -17,7 +17,7 @@ type SortBy = 'name' | 'count';
export default {
inProduction: true,
inDevelopment: true,
inDevelopment: false,
inPublic: true,
command: new SlashCommandBuilder()
+1 -1
View File
@@ -13,7 +13,7 @@ import { AccountInfo } from '../types/accountInfo.js';
export default {
inProduction: true,
inDevelopment: true,
inDevelopment: false,
inPublic: true,
command: new SlashCommandBuilder()
+1 -1
View File
@@ -12,7 +12,7 @@ import { ClanList } from '../types/clanList.js';
export default {
inProduction: true,
inDevelopment: true,
inDevelopment: false,
inPublic: true,
command: new SlashCommandBuilder()
+1 -1
View File
@@ -13,7 +13,7 @@ import { AccountList } from '../types/accountList.js';
export default {
inProduction: true,
inDevelopment: true,
inDevelopment: false,
inPublic: true,
command: new SlashCommandBuilder()
+1 -1
View File
@@ -9,7 +9,7 @@ import { CommandRegistry } from '../events/interactionCreate.js';
export default {
inProduction: true,
inDevelopment: true,
inDevelopment: false,
inPublic: true,
command: new SlashCommandBuilder()
+1 -1
View File
@@ -40,7 +40,7 @@ import { PlayerClanData } from '../types/playerClanData.js';
export default {
inProduction: true,
inDevelopment: true,
inDevelopment: false,
inPublic: true,
command: new SlashCommandBuilder()
+1 -1
View File
@@ -40,7 +40,7 @@ import { AccountInfo, AllStats } from '../types/accountInfo.js';
export default {
inProduction: true,
inDevelopment: true,
inDevelopment: false,
inPublic: true,
command: new SlashCommandBuilder()
+1 -1
View File
@@ -32,7 +32,7 @@ import { PlayerClanData } from '../types/playerClanData.js';
export default {
inProduction: true,
inDevelopment: true,
inDevelopment: false,
inPublic: true,
command: new SlashCommandBuilder()
+1 -1
View File
@@ -14,7 +14,7 @@ import { PlayerClanData } from '../types/playerClanData.js';
export default {
inProduction: true,
inDevelopment: true,
inDevelopment: false,
inPublic: true,
command: new SlashCommandBuilder()
+22 -43
View File
@@ -1,37 +1,20 @@
import { WargamingResponse } from '../../types/wargamingResponse.js';
import URLToBase64 from '../ui/URLToBase64.js';
/*
"1": {
"name": "T-34",
"nation": "ussr",
"is_premium": false,
"tier": 5,
"cost": {
"price_credit": 400000,
"price_gold": 0
},
"images": {
"preview": "/api/bs-cache/tank-icons/https%3A%2F%2Fglossary-eu-static.gcdn.co%2Ficons%2Fwotb%2Fcurrent%2Fuploaded%2Fvehicles%2Fhd_thumbnail%2FT-34.png",
"normal": "http://glossary-eu-static.gcdn.co/icons/wotb/current/uploaded/vehicles/hd/T-34.png"
},
"tank_id": 1,
"type": "mediumTank",
"description": "The legend of the Soviet armored forces and the most widely-produced Soviet tank of World War II, with a total of 33,805 vehicles manufactured. Three variants of this model were produced at several Soviet factories from 1940 through 1944."
},
*/
export interface TankopediaEntry {
name: string;
nation: string;
is_premium: boolean;
tier: number;
cost: { price_credit: number; price_gold: number };
images: { preview: string; normal: string };
tank_id: number;
type: string;
description: string;
}
export interface Tankopedia {
[id: number]: {
name: string;
nation: string;
is_premium: boolean;
tier: number;
cost: { price_credit: number; price_gold: number };
images: { preview: string; normal: string };
tank_id: number;
type: string;
description: string;
};
[id: number]: TankopediaEntry;
}
console.log('Caching tankopedia...');
@@ -56,16 +39,12 @@ export const TANK_IDS = Object.keys(tankopedia).map((id) => Number(id));
export const TANKS = TANK_IDS.map((id) => tankopedia[id]);
export const TANK_NAMES = TANKS.map((tank) => tank.name);
// console.log('Encoding tank images...');
// await Promise.all(
// Object.entries(tankopedia).map(async ([, tank]) => {
// try {
// tank.images.normal = await URLToBase64(tank.images.normal);
// } catch (error) {
// console.warn(
// `Failed to encode tank image for ${tank.images.normal}: ${error}`,
// );
// }
// }),
// );
// console.log('Encoded tank images');
console.log('Encoding tank images...');
await Promise.all(
Object.entries(tankopedia).map(async ([, tank]) => {
if (tank.images.normal) {
tank.images.normal = await URLToBase64(tank.images.normal);
}
}),
);
console.log('Encoded tank images');