main
Bob Mottram 2021-07-09 21:24:56 +01:00
parent 8a1e196b15
commit 266eb1af47
1 changed files with 13 additions and 13 deletions

View File

@ -3242,9 +3242,10 @@ class PubServer(BaseHTTPRequestHandler):
'webp': 'webp', 'webp': 'webp',
'avif': 'avif' 'avif': 'avif'
} }
for mimeExt, ext in imageMedia: for mimeExt, ext in imageMedia.items():
if self.headers['Content-type'].endswith(mimeExt): if self.headers['Content-type'].endswith(mimeExt):
mediaFilename = mediaFilenameBase + '.' + ext mediaFilename = mediaFilenameBase + '.' + ext
break
with open(mediaFilename, 'wb') as avFile: with open(mediaFilename, 'wb') as avFile:
avFile.write(mediaBytes) avFile.write(mediaBytes)
if debug: if debug:
@ -10128,18 +10129,17 @@ class PubServer(BaseHTTPRequestHandler):
self._304() self._304()
return True return True
mediaImageType = 'png' mediaImageType = 'png'
if avatarFile.endswith('.png'): extensionsToMime = {
mediaImageType = 'png' 'jpg': 'jpeg',
elif avatarFile.endswith('.jpg'): 'gif': 'gif',
mediaImageType = 'jpeg' 'avif': 'avif',
elif avatarFile.endswith('.gif'): 'svg': 'svg+xml',
mediaImageType = 'gif' 'webp': 'webp'
elif avatarFile.endswith('.avif'): }
mediaImageType = 'avif' for ext, mimeExt in extensionsToMime.items():
elif avatarFile.endswith('.svg'): if avatarFile.endswith('.' + ext):
mediaImageType = 'svg+xml' mediaImageType = mimeExt
else: break
mediaImageType = 'webp'
with open(avatarFilename, 'rb') as avFile: with open(avatarFilename, 'rb') as avFile:
mediaBinary = avFile.read() mediaBinary = avFile.read()
self._set_headers_etag(avatarFilename, self._set_headers_etag(avatarFilename,