prefer mime type to avoid having to parse messy urls

This commit is contained in:
rimu 2024-06-18 20:12:20 +08:00
parent 4f3a8b1d74
commit be58f833ef

View file

@ -974,13 +974,13 @@ def make_image_sizes_async(file_id, thumbnail_width, medium_width, directory):
source_image = source_image_response.content source_image = source_image_response.content
source_image_response.close() source_image_response.close()
file_ext = os.path.splitext(file.source_url)[1] content_type_parts = content_type.split('/')
# fall back to parsing the http content type if the url does not contain a file extension if content_type_parts:
if file_ext == '': file_ext = '.' + content_type_parts[-1]
content_type_parts = content_type.split('/') if file_ext == '.jpeg':
if content_type_parts: file_ext = '.jpg'
file_ext = '.' + content_type_parts[-1]
else: else:
file_ext = os.path.splitext(file.source_url)[1]
file_ext = file_ext.replace('%3f', '?') # sometimes urls are not decoded properly file_ext = file_ext.replace('%3f', '?') # sometimes urls are not decoded properly
if '?' in file_ext: if '?' in file_ext:
file_ext = file_ext.split('?')[0] file_ext = file_ext.split('?')[0]