main
Bob Mottram 2020-12-12 14:23:14 +00:00
parent eb39892e78
commit b7e8ad6e7a
1 changed files with 20 additions and 30 deletions

View File

@ -281,36 +281,26 @@ def updateAvatarImageCache(session, baseDir: str, httpPrefix: str,
return None return None
actorStr = actor.replace('/', '-') actorStr = actor.replace('/', '-')
avatarImagePath = baseDir + '/cache/avatars/' + actorStr avatarImagePath = baseDir + '/cache/avatars/' + actorStr
if avatarUrl.endswith('.png') or \
'.png?' in avatarUrl: # try different image types
sessionHeaders = { imageFormats = {
'Accept': 'image/png' 'png': 'png',
} 'jpg': 'jpeg',
avatarImageFilename = avatarImagePath + '.png' 'jpeg': 'jpeg',
elif (avatarUrl.endswith('.jpg') or 'gif': 'gif',
avatarUrl.endswith('.jpeg') or 'webp': 'webp',
'.jpg?' in avatarUrl or 'avif': 'avif'
'.jpeg?' in avatarUrl): }
sessionHeaders = { avatarImageFilename = None
'Accept': 'image/jpeg' for imFormat, mimeType in imageFormats.items():
} if avatarUrl.endswith('.' + imFormat) or \
avatarImageFilename = avatarImagePath + '.jpg' '.' + imFormat + '?' in avatarUrl:
elif avatarUrl.endswith('.gif') or '.gif?' in avatarUrl: sessionHeaders = {
sessionHeaders = { 'Accept': 'image/' + mimeType
'Accept': 'image/gif' }
} avatarImageFilename = avatarImagePath + '.' + imFormat
avatarImageFilename = avatarImagePath + '.gif'
elif avatarUrl.endswith('.webp') or '.webp?' in avatarUrl: if not avatarImageFilename:
sessionHeaders = {
'Accept': 'image/webp'
}
avatarImageFilename = avatarImagePath + '.webp'
elif avatarUrl.endswith('.avif') or '.avif?' in avatarUrl:
sessionHeaders = {
'Accept': 'image/avif'
}
avatarImageFilename = avatarImagePath + '.avif'
else:
return None return None
if (not os.path.isfile(avatarImageFilename) or force) and allowDownloads: if (not os.path.isfile(avatarImageFilename) or force) and allowDownloads: