From 76ca9aa8f48fb68cb557bd1a39d02718f71bbd23 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Sat, 22 Jun 2024 16:14:56 +0800 Subject: [PATCH] improve thumbnail generation reliability --- app/activitypub/util.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/activitypub/util.py b/app/activitypub/util.py index c03fe87f..d4412d2b 100644 --- a/app/activitypub/util.py +++ b/app/activitypub/util.py @@ -982,7 +982,15 @@ def make_image_sizes_async(file_id, thumbnail_width, medium_width, directory): content_type_parts = content_type.split('/') if content_type_parts: - file_ext = '.' + content_type_parts[-1] + # content type headers often are just 'image/jpeg' but sometimes 'image/jpeg;charset=utf8' + + # Remove ;charset=whatever + main_part = content_type.split(';')[0] + + # Split the main part on the '/' character and take the second part + file_ext = '.' + main_part.split('/')[1] + file_ext = file_ext.strip() # just to be sure + if file_ext == '.jpeg': file_ext = '.jpg' else: