From cb530652247e102835a477a1783f8e9b108ad6e8 Mon Sep 17 00:00:00 2001 From: idanran <96647698+idanran@users.noreply.github.com> Date: Sun, 23 Jul 2023 09:04:45 +0000 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20Telegram=20=E7=9A=84=E8=B4=B4?= =?UTF-8?q?=E7=BA=B8=E6=8B=BF=E4=B8=8D=E5=88=B0=E5=87=86=E7=A1=AE=E7=9A=84?= =?UTF-8?q?=20mime?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- adapters/telegram/package.json | 1 + adapters/telegram/src/bot.ts | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/adapters/telegram/package.json b/adapters/telegram/package.json index 877d4a7c..0117307b 100644 --- a/adapters/telegram/package.json +++ b/adapters/telegram/package.json @@ -33,6 +33,7 @@ "@satorijs/satori": "^2.5.4" }, "dependencies": { + "file-type": "^16.5.4", "form-data": "^4.0.0" } } diff --git a/adapters/telegram/src/bot.ts b/adapters/telegram/src/bot.ts index 8454d5f9..f49a8bd1 100644 --- a/adapters/telegram/src/bot.ts +++ b/adapters/telegram/src/bot.ts @@ -4,6 +4,7 @@ import { adaptAuthorMeta, adaptGuildMember, adaptMessageMeta, adaptUser } from ' import { TelegramMessageEncoder } from './message' import { HttpServer } from './server' import { HttpPolling } from './polling' +import FileType from 'file-type' const logger = new Logger('telegram') @@ -266,11 +267,14 @@ export class TelegramBot exte } } - async $getFileFromPath(filePath: string) { + async $getFileFromPath(filePath: string, retrieveMime: boolean) { if (this.server) { return { url: `${this.server}/${filePath}` } } - const { mime, data } = await this.$getFile(filePath) + let { mime, data } = await this.$getFile(filePath) + if (mime === 'application/octet-stream') { + mime = await FileType.fromBuffer(data)?.mime + } const base64 = `data:${mime};base64,` + arrayBufferToBase64(data) return { url: base64 } } From 55d5106246df8ccde96a13ff015350fc41a03a47 Mon Sep 17 00:00:00 2001 From: idanran <96647698+idanran@users.noreply.github.com> Date: Sun, 23 Jul 2023 09:06:11 +0000 Subject: [PATCH 2/2] chore --- adapters/telegram/src/bot.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adapters/telegram/src/bot.ts b/adapters/telegram/src/bot.ts index f49a8bd1..2e9305a3 100644 --- a/adapters/telegram/src/bot.ts +++ b/adapters/telegram/src/bot.ts @@ -267,7 +267,7 @@ export class TelegramBot exte } } - async $getFileFromPath(filePath: string, retrieveMime: boolean) { + async $getFileFromPath(filePath: string) { if (this.server) { return { url: `${this.server}/${filePath}` } }