Skip to content

Commit

Permalink
chore: add basic logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Myphz committed Jan 2, 2024
1 parent c326354 commit 4cf2eee
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/routes/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/telegram/telegram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 4cf2eee

Please sign in to comment.