tgbridge: shrink oversize gifs sent as files, not just as animations

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 <[email protected]>
This commit is contained in:
esefandClaude Opus 5 committed 2026-10-31 14:41:11 +03:00
1 parent 78c755a7a2
commit 9d1f6778c4
1 file changed
+8
+8
View File
@@ -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: