From c618fb8ba31a909c4b3466aa4de43c97738b0738 Mon Sep 17 00:00:00 2001 From: miruka Date: Sun, 8 Mar 2020 08:10:27 -0400 Subject: [PATCH] Don't upload thumbnail if heavier than original --- TODO.md | 1 - src/backend/matrix_client.py | 10 +++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/TODO.md b/TODO.md index d129d1bf..29c26760 100644 --- a/TODO.md +++ b/TODO.md @@ -8,7 +8,6 @@ - nio ClientTimeout -- no thumb if bigger than original - Handle upload file size limit - Handle set avatar upload errors - Confirmation box after picking file to upload diff --git a/src/backend/matrix_client.py b/src/backend/matrix_client.py index e81714e6..5203f8c7 100644 --- a/src/backend/matrix_client.py +++ b/src/backend/matrix_client.py @@ -827,10 +827,14 @@ class MatrixClient(nio.AsyncClient): thumb.convert("RGB").save(out, "JPEG", optimize=True) mime = "image/jpeg" - data = out.getvalue() + thumb_data = out.getvalue() + thumb_size = len(thumb_data) - info = MatrixImageInfo(thumb.width, thumb.height, mime, len(data)) - return (data, info) + if thumb_size >= len(data): + raise UneededThumbnail() + + info = MatrixImageInfo(thumb.width, thumb.height, mime, thumb_size) + return (thumb_data, info) async def upload(