From 4cf2eeea5a3c02dade6b0ebcc8cd205cfcf2d3f8 Mon Sep 17 00:00:00 2001 From: Myphz Date: Tue, 2 Jan 2024 14:37:26 +0100 Subject: [PATCH] chore: add basic logs --- src/routes/files.ts | 2 ++ src/telegram/telegram.ts | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/routes/files.ts b/src/routes/files.ts index 462d3e9..c3dca5f 100644 --- a/src/routes/files.ts +++ b/src/routes/files.ts @@ -17,7 +17,9 @@ export const FilesAPI: FastifyPluginCallback = async (fastify, _, done) => { // saveRequestFiles saves files in tmp directory. // This is to avoid working with req.files(), which is an async iterator... and a pain to work with. // Files from saveRequestFiles() have a useless toBuffer method, so it needs to be replaced. + console.log("Saving file to disk..."); const files = (await req.saveRequestFiles()).map((file) => ({ ...file, toBuffer: () => readFile(file.filepath) })); + console.log(`Start upload of ${files.length} files...`); const ret = await uploadFiles(files); res.code(201); diff --git a/src/telegram/telegram.ts b/src/telegram/telegram.ts index 8eff948..e56a1a0 100644 --- a/src/telegram/telegram.ts +++ b/src/telegram/telegram.ts @@ -10,10 +10,12 @@ const bot = new TelegramBot(TRIPS_BOT_API_TOKEN, { filepath: false }); export async function uploadFiles(files: MultipartFile[]) { // This library has incorrect typescript typings... InputMediaDocument missing + console.log("Reading files from disk..."); const media = (await Promise.all( files.map(async (file) => ({ media: await file.toBuffer(), type: "document" })), )) as unknown as InputMediaPhoto[]; + console.log("Uploading to Telegram..."); return (await bot.sendMediaGroup(CHAT_ID, media)).reduce( (prev, curr, i) => ({ ...prev,