From 9d1f6778c44142e782dc125366a18b070c5935b2 Mon Sep 17 00:00:00 2001 From: esefxdz Date: Sat, 31 Oct 2026 14:41:11 +0300 Subject: [PATCH] tgbridge: shrink oversize gifs sent as files, not just as animations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A .gif uploaded as a document never matches the animation branch, so it went to discord untouched and came back 413. First real test of the local api server hit exactly this: a 27.2 MB gif fetched fine, then bounced. Same ladder, same .gif out — that file lands at 5.73 MB. Co-Authored-By: Claude Opus 5 --- tgbridge/forwarder.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tgbridge/forwarder.py b/tgbridge/forwarder.py index d5f3db4..0b8f175 100644 --- a/tgbridge/forwarder.py +++ b/tgbridge/forwarder.py @@ -315,6 +315,14 @@ class TelegramForwarder: if document: data, filename = await self._download(document.file_id) + # a gif sent as a file never reaches the animation branch, so it + # went to discord at full size — same ladder, same .gif out + is_gif = (doc_mime == "image/gif" + or filename.lower().endswith(".gif")) + if is_gif and len(data) > media.MAX_CONVERTED_BYTES: + smaller = await media.to_gif(data, ".gif") + if smaller: + return [(filename, smaller)], "" return [(filename, data)], "" if message.voice: