diff --git a/src/bot.ts b/src/bot.ts index c76df58a4f8d65a0eec5d452aee06d11717304c7..d2393a043515ead322eeed2adca121cc0bc570ba 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -45,6 +45,14 @@ interface IThirdPartyLookup { protocol: string; } +interface IMatrixMediaInfo { + w?: number; + h?: number; + mimetype: string; + size: number; + duration?: number; +} + export class DiscordBot { private config: DiscordBridgeConfig; private clientFactory: DiscordClientFactory; @@ -629,14 +637,20 @@ export class DiscordBot { await Util.AsyncForEach(msg.attachments.array(), async (attachment) => { const content = await Util.UploadContentFromUrl(attachment.url, intent, attachment.filename); const fileMime = mime.lookup(attachment.filename); - const msgtype = attachment.height ? "m.image" : "m.file"; + const type = fileMime.split("/")[0]; + let msgtype = { + audio: "m.audio", + image: "m.image", + video: "m.video", + }[type]; + if (!msgtype) { + msgtype = "m.file"; + } const info = { - h: null, mimetype: fileMime, size: attachment.filesize, - w: null, - }; - if (msgtype === "m.image") { + } as IMatrixMediaInfo; + if (msgtype === "m.image" || msgtype === "m.video") { info.w = attachment.width; info.h = attachment.height; }