forked from pinks/eris
1
0
Fork 0

log upload type and bytes

This commit is contained in:
pinks 2023-10-15 13:12:31 +02:00
parent 07fc0c71f2
commit 843f6d9103
1 changed files with 10 additions and 0 deletions

View File

@ -63,12 +63,16 @@ export async function processUploadQueue() {
]);
// parse files from reply JSON
let size = 0;
const types = new Set<string>();
const inputFiles = await Promise.all(
state.imageKeys.map(async (fileKey, idx) => {
const imageBuffer = await fs.get(fileKey).then((entry) => entry.value);
if (!imageBuffer) throw new Error("File not found");
const imageType = await fileTypeFromBuffer(imageBuffer);
if (!imageType) throw new Error("Image has unknown type");
size += imageBuffer.byteLength;
types.add(imageType.ext);
return InputMediaBuilder.photo(
new InputFile(imageBuffer, `image${idx}.${imageType.ext}`),
// if it can fit, add caption for first photo
@ -121,6 +125,12 @@ export async function processUploadQueue() {
globalStats.userIds = [...userIdSet];
}
logger().debug(
`Uploaded ${state.imageKeys.length} ${[...types].join(",")} images (${
Math.trunc(size / 1024)
}kB) for ${formatUserChat(state)}`,
);
// delete the status message
await bot.api.deleteMessage(state.replyMessage.chat.id, state.replyMessage.message_id)
.catch(() => undefined);