Don't upload thumbnail if heavier than original

This commit is contained in:
miruka 2020-03-08 08:10:27 -04:00
parent e1b26d1ec7
commit c618fb8ba3
2 changed files with 7 additions and 4 deletions

View File

@ -8,7 +8,6 @@
- nio ClientTimeout - nio ClientTimeout
- no thumb if bigger than original
- Handle upload file size limit - Handle upload file size limit
- Handle set avatar upload errors - Handle set avatar upload errors
- Confirmation box after picking file to upload - Confirmation box after picking file to upload

View File

@ -827,10 +827,14 @@ class MatrixClient(nio.AsyncClient):
thumb.convert("RGB").save(out, "JPEG", optimize=True) thumb.convert("RGB").save(out, "JPEG", optimize=True)
mime = "image/jpeg" mime = "image/jpeg"
data = out.getvalue() thumb_data = out.getvalue()
thumb_size = len(thumb_data)
info = MatrixImageInfo(thumb.width, thumb.height, mime, len(data)) if thumb_size >= len(data):
return (data, info) raise UneededThumbnail()
info = MatrixImageInfo(thumb.width, thumb.height, mime, thumb_size)
return (thumb_data, info)
async def upload( async def upload(