mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 10:47:04 +02:00
feat: encode images on a separate thread
This commit is contained in:
1 parent
804fa58d27
commit
58c68968e7
18 files changed
+42
-63
No files matched your search
@@ -18,6 +18,7 @@
|
||||
"fuzzysort": "^2.0.4",
|
||||
"lodash.startcase": "^4.4.0",
|
||||
"markdown-escape": "^2.0.0",
|
||||
"node-worker-threads-pool": "^1.5.1",
|
||||
"react": "^18.2.0",
|
||||
"satori": "^0.9.1"
|
||||
},
|
||||
|
||||
@@ -46,7 +46,5 @@ export default {
|
||||
),
|
||||
],
|
||||
});
|
||||
|
||||
console.log("Displaying bot's debug information");
|
||||
},
|
||||
} satisfies CommandRegistry;
|
||||
@@ -171,9 +171,5 @@ export default {
|
||||
? [positiveEmbed(title, body)]
|
||||
: [negativeEmbed(title, body)],
|
||||
});
|
||||
|
||||
console.log(
|
||||
`Displaying ${server}/${id}'s eligibility information for ${clan}`,
|
||||
);
|
||||
},
|
||||
} satisfies CommandRegistry;
|
||||
@@ -39,7 +39,5 @@ export default {
|
||||
),
|
||||
],
|
||||
});
|
||||
|
||||
console.log('Displaying help information');
|
||||
},
|
||||
} satisfies CommandRegistry;
|
||||
@@ -83,10 +83,6 @@ export default {
|
||||
),
|
||||
],
|
||||
});
|
||||
|
||||
console.log(
|
||||
`Displaying inactive members in ${clanInfo[id].name} for ${threshold} days`,
|
||||
);
|
||||
},
|
||||
|
||||
autocomplete: clanAutocomplete,
|
||||
|
||||
@@ -93,10 +93,6 @@ export default {
|
||||
),
|
||||
],
|
||||
});
|
||||
|
||||
console.log(
|
||||
`Displaying ${accountInfo[id].nickname}'s owned tanks in tier ${tier}`,
|
||||
);
|
||||
},
|
||||
|
||||
autocomplete: usernameAutocomplete,
|
||||
|
||||
@@ -75,8 +75,6 @@ export default {
|
||||
),
|
||||
],
|
||||
});
|
||||
|
||||
console.log(`Displaying player info for ${accounts[id].nickname}`);
|
||||
},
|
||||
|
||||
autocomplete: usernameAutocomplete,
|
||||
|
||||
@@ -59,8 +59,6 @@ export default {
|
||||
),
|
||||
],
|
||||
});
|
||||
|
||||
console.log(`Displaying player info for ${accountInfo.nickname}`);
|
||||
},
|
||||
|
||||
autocomplete: usernameAutocomplete,
|
||||
|
||||
@@ -50,7 +50,5 @@ export default {
|
||||
),
|
||||
],
|
||||
});
|
||||
|
||||
console.log(`Clan search results for "${clan}"`);
|
||||
},
|
||||
} satisfies CommandRegistry;
|
||||
@@ -58,7 +58,5 @@ export default {
|
||||
),
|
||||
],
|
||||
});
|
||||
|
||||
console.log(`Player search results for "${name}"`);
|
||||
},
|
||||
} satisfies CommandRegistry;
|
||||
@@ -41,7 +41,5 @@ export default {
|
||||
),
|
||||
],
|
||||
});
|
||||
|
||||
console.log(`Tank search results for "${tank}"`);
|
||||
},
|
||||
} satisfies CommandRegistry;
|
||||
@@ -173,7 +173,6 @@ export default {
|
||||
components: [actionRow],
|
||||
});
|
||||
|
||||
console.log(`Showing stats for ${accountInfo[id].nickname}`);
|
||||
},
|
||||
|
||||
autocomplete: usernameAutocomplete,
|
||||
|
||||
@@ -116,8 +116,6 @@ export default {
|
||||
files: [image],
|
||||
components: [actionRow],
|
||||
});
|
||||
|
||||
console.log(`Showing stats for ${accountInfo[id].nickname}`);
|
||||
},
|
||||
|
||||
autocomplete: (interaction) => {
|
||||
|
||||
@@ -194,7 +194,6 @@ export default {
|
||||
components: [actionRow],
|
||||
});
|
||||
|
||||
console.log(`Showing daily breakdown for ${accountInfo[id].nickname}`);
|
||||
},
|
||||
|
||||
autocomplete: usernameAutocomplete,
|
||||
|
||||
@@ -48,10 +48,6 @@ export default {
|
||||
],
|
||||
});
|
||||
|
||||
console.warn(
|
||||
`${interaction.user.username} failed to verify because of no nickname permission.`,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -83,10 +79,6 @@ export default {
|
||||
],
|
||||
});
|
||||
|
||||
console.warn(
|
||||
`${interaction.user.username} failed to verify because of no manage roles permission.`,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -106,10 +98,6 @@ export default {
|
||||
),
|
||||
],
|
||||
});
|
||||
|
||||
console.log(
|
||||
`${interaction.user.username} verified as ${accountInfo[id].nickname}${clanTag}`,
|
||||
);
|
||||
} catch (error) {
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
@@ -121,8 +109,6 @@ export default {
|
||||
),
|
||||
],
|
||||
});
|
||||
|
||||
console.warn('Failed to verify because of higher permissions.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { StaticPool } from 'node-worker-threads-pool';
|
||||
import { WargamingResponse } from '../../types/wargamingResponse.js';
|
||||
import URLToBase64 from '../ui/URLToBase64.js';
|
||||
|
||||
export interface TankopediaEntry {
|
||||
name: string;
|
||||
@@ -39,12 +39,38 @@ 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]) => {
|
||||
if (tank.images.normal) {
|
||||
tank.images.normal = await URLToBase64(tank.images.normal);
|
||||
}
|
||||
}),
|
||||
);
|
||||
console.log('Encoded tank images');
|
||||
const imageEncodingStaticPool = new StaticPool({
|
||||
size: 1,
|
||||
task: async (data: Tankopedia) => {
|
||||
console.log('Encoding tank images...');
|
||||
|
||||
const encoded: [number, string][] = [];
|
||||
|
||||
await Promise.all(
|
||||
Object.entries(data as Tankopedia).map(
|
||||
async ([, tank]: [string, TankopediaEntry]) => {
|
||||
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')}`;
|
||||
encoded.push([tank.tank_id, base64]);
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
console.log('Encoded tank images');
|
||||
|
||||
return encoded;
|
||||
},
|
||||
});
|
||||
|
||||
imageEncodingStaticPool.exec(tankopedia).then((encoded) => {
|
||||
console.log('Implementing encoded images...');
|
||||
encoded.forEach(([tankId, image]) => {
|
||||
tankopedia[tankId].images.normal = image;
|
||||
});
|
||||
console.log('Implemented encoded images');
|
||||
});
|
||||
@@ -1,9 +0,0 @@
|
||||
export default async function URLToBase64(URL: string) {
|
||||
const response = await fetch(URL);
|
||||
const blob = await response.arrayBuffer();
|
||||
const base64 = `data:${response.headers.get(
|
||||
'content-type',
|
||||
)};base64,${Buffer.from(blob).toString('base64')}`;
|
||||
|
||||
return base64;
|
||||
}
|
||||
@@ -577,6 +577,11 @@ nanoid@^3.3.6:
|
||||
resolved "https://registry.npmjs.org/nanoid/-/nanoid-3.3.6.tgz"
|
||||
integrity sha512-BGcqMMJuToF7i1rt+2PWSNVnWIkGCU78jBG3RxO/bZlnZPK2Cmi2QaffxGO/2RvWi9sL+FAiRiXMgsyxQ1DIDA==
|
||||
|
||||
node-worker-threads-pool@^1.5.1:
|
||||
version "1.5.1"
|
||||
resolved "https://registry.yarnpkg.com/node-worker-threads-pool/-/node-worker-threads-pool-1.5.1.tgz#1034303e10bb63a541ec74ae26559e9dff355f27"
|
||||
integrity sha512-7TXAhpMm+jO4MfESxYLtMGSnJWv+itdNHMdaFmeZuPXxwFGU90mtEB42BciUULXOUAxYBfXILAuvrSG3rQZ7mw==
|
||||
|
||||
pako@^0.2.5:
|
||||
version "0.2.9"
|
||||
resolved "https://registry.yarnpkg.com/pako/-/pako-0.2.9.tgz#f3f7522f4ef782348da8161bad9ecfd51bf83a75"
|
||||
|
||||
Reference in new issue
Block a user