mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +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",
|
"fuzzysort": "^2.0.4",
|
||||||
"lodash.startcase": "^4.4.0",
|
"lodash.startcase": "^4.4.0",
|
||||||
"markdown-escape": "^2.0.0",
|
"markdown-escape": "^2.0.0",
|
||||||
|
"node-worker-threads-pool": "^1.5.1",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"satori": "^0.9.1"
|
"satori": "^0.9.1"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -46,7 +46,5 @@ export default {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("Displaying bot's debug information");
|
|
||||||
},
|
},
|
||||||
} satisfies CommandRegistry;
|
} satisfies CommandRegistry;
|
||||||
@@ -171,9 +171,5 @@ export default {
|
|||||||
? [positiveEmbed(title, body)]
|
? [positiveEmbed(title, body)]
|
||||||
: [negativeEmbed(title, body)],
|
: [negativeEmbed(title, body)],
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(
|
|
||||||
`Displaying ${server}/${id}'s eligibility information for ${clan}`,
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
} satisfies CommandRegistry;
|
} satisfies CommandRegistry;
|
||||||
@@ -39,7 +39,5 @@ export default {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('Displaying help information');
|
|
||||||
},
|
},
|
||||||
} satisfies CommandRegistry;
|
} satisfies CommandRegistry;
|
||||||
@@ -83,10 +83,6 @@ export default {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(
|
|
||||||
`Displaying inactive members in ${clanInfo[id].name} for ${threshold} days`,
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
autocomplete: clanAutocomplete,
|
autocomplete: clanAutocomplete,
|
||||||
|
|||||||
@@ -93,10 +93,6 @@ export default {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(
|
|
||||||
`Displaying ${accountInfo[id].nickname}'s owned tanks in tier ${tier}`,
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
autocomplete: usernameAutocomplete,
|
autocomplete: usernameAutocomplete,
|
||||||
|
|||||||
@@ -75,8 +75,6 @@ export default {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(`Displaying player info for ${accounts[id].nickname}`);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
autocomplete: usernameAutocomplete,
|
autocomplete: usernameAutocomplete,
|
||||||
|
|||||||
@@ -59,8 +59,6 @@ export default {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(`Displaying player info for ${accountInfo.nickname}`);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
autocomplete: usernameAutocomplete,
|
autocomplete: usernameAutocomplete,
|
||||||
|
|||||||
@@ -50,7 +50,5 @@ export default {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(`Clan search results for "${clan}"`);
|
|
||||||
},
|
},
|
||||||
} satisfies CommandRegistry;
|
} satisfies CommandRegistry;
|
||||||
@@ -58,7 +58,5 @@ export default {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(`Player search results for "${name}"`);
|
|
||||||
},
|
},
|
||||||
} satisfies CommandRegistry;
|
} satisfies CommandRegistry;
|
||||||
@@ -41,7 +41,5 @@ export default {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(`Tank search results for "${tank}"`);
|
|
||||||
},
|
},
|
||||||
} satisfies CommandRegistry;
|
} satisfies CommandRegistry;
|
||||||
@@ -173,7 +173,6 @@ export default {
|
|||||||
components: [actionRow],
|
components: [actionRow],
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(`Showing stats for ${accountInfo[id].nickname}`);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
autocomplete: usernameAutocomplete,
|
autocomplete: usernameAutocomplete,
|
||||||
|
|||||||
@@ -116,8 +116,6 @@ export default {
|
|||||||
files: [image],
|
files: [image],
|
||||||
components: [actionRow],
|
components: [actionRow],
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(`Showing stats for ${accountInfo[id].nickname}`);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
autocomplete: (interaction) => {
|
autocomplete: (interaction) => {
|
||||||
|
|||||||
@@ -194,7 +194,6 @@ export default {
|
|||||||
components: [actionRow],
|
components: [actionRow],
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(`Showing daily breakdown for ${accountInfo[id].nickname}`);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
autocomplete: usernameAutocomplete,
|
autocomplete: usernameAutocomplete,
|
||||||
|
|||||||
@@ -48,10 +48,6 @@ export default {
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
console.warn(
|
|
||||||
`${interaction.user.username} failed to verify because of no nickname permission.`,
|
|
||||||
);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,10 +79,6 @@ export default {
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
console.warn(
|
|
||||||
`${interaction.user.username} failed to verify because of no manage roles permission.`,
|
|
||||||
);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,10 +98,6 @@ export default {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(
|
|
||||||
`${interaction.user.username} verified as ${accountInfo[id].nickname}${clanTag}`,
|
|
||||||
);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [
|
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 { WargamingResponse } from '../../types/wargamingResponse.js';
|
||||||
import URLToBase64 from '../ui/URLToBase64.js';
|
|
||||||
|
|
||||||
export interface TankopediaEntry {
|
export interface TankopediaEntry {
|
||||||
name: string;
|
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 TANKS = TANK_IDS.map((id) => tankopedia[id]);
|
||||||
export const TANK_NAMES = TANKS.map((tank) => tank.name);
|
export const TANK_NAMES = TANKS.map((tank) => tank.name);
|
||||||
|
|
||||||
console.log('Encoding tank images...');
|
const imageEncodingStaticPool = new StaticPool({
|
||||||
await Promise.all(
|
size: 1,
|
||||||
Object.entries(tankopedia).map(async ([, tank]) => {
|
task: async (data: Tankopedia) => {
|
||||||
if (tank.images.normal) {
|
console.log('Encoding tank images...');
|
||||||
tank.images.normal = await URLToBase64(tank.images.normal);
|
|
||||||
}
|
const encoded: [number, string][] = [];
|
||||||
}),
|
|
||||||
);
|
await Promise.all(
|
||||||
console.log('Encoded tank images');
|
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"
|
resolved "https://registry.npmjs.org/nanoid/-/nanoid-3.3.6.tgz"
|
||||||
integrity sha512-BGcqMMJuToF7i1rt+2PWSNVnWIkGCU78jBG3RxO/bZlnZPK2Cmi2QaffxGO/2RvWi9sL+FAiRiXMgsyxQ1DIDA==
|
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:
|
pako@^0.2.5:
|
||||||
version "0.2.9"
|
version "0.2.9"
|
||||||
resolved "https://registry.yarnpkg.com/pako/-/pako-0.2.9.tgz#f3f7522f4ef782348da8161bad9ecfd51bf83a75"
|
resolved "https://registry.yarnpkg.com/pako/-/pako-0.2.9.tgz#f3f7522f4ef782348da8161bad9ecfd51bf83a75"
|
||||||
|
|||||||
Reference in new issue
Block a user