From d2edf12fdfb2179054752691665a0d4c746ceabd Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Thu, 3 Oct 2019 10:57:52 +0300 Subject: [PATCH] Fix weird mime type bug in alpine/magic --- example-config.yaml | 2 +- mautrix_telegram/util/file_transfer.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/example-config.yaml b/example-config.yaml index 2cba1761..010dbb2c 100644 --- a/example-config.yaml +++ b/example-config.yaml @@ -178,7 +178,7 @@ bridge: args: width: 256 height: 256 - background: "ffffff" + background: "020202" # Whether to bridge Telegram bot messages as m.notices or m.texts. bot_messages_as_notices: true diff --git a/mautrix_telegram/util/file_transfer.py b/mautrix_telegram/util/file_transfer.py index bcc638ce..f08ed177 100644 --- a/mautrix_telegram/util/file_transfer.py +++ b/mautrix_telegram/util/file_transfer.py @@ -202,7 +202,10 @@ async def _unlocked_transfer_file_to_matrix(client: MautrixTelegramClient, inten mime_type = magic.from_buffer(file, mime=True) image_converted = False - if mime_type == "application/gzip" and is_sticker and tgs_convert: + # A weird bug in alpine/magic makes it return application/octet-stream for gzips... + if is_sticker and tgs_convert and (mime_type == "application/gzip" or ( + mime_type == "application/octet-stream" + and magic.from_buffer(file).startswith("gzip"))): mime_type, file, width, height, thumbnail = await convert_tgs_to( file, tgs_convert["target"], **tgs_convert["args"]) image_converted = mime_type != "application/gzip"