Avatar cache filenames

main2
Bob Mottram 2019-09-14 18:16:03 +01:00
parent 47225c686b
commit 2975601956
1 changed files with 11 additions and 9 deletions

View File

@ -47,16 +47,18 @@ def updateAvatarImageCache(session,baseDir: str,httpPrefix: str,actor: str,avata
""" """
if not avatarUrl: if not avatarUrl:
return None return None
avatarImageFilename=baseDir+'/cache/avatars/'+avatarUrl.replace('/','#')
if not os.path.isfile(avatarImageFilename) or force:
if avatarUrl.endswith('.png'): if avatarUrl.endswith('.png'):
sessionHeaders = {'Accept': 'image/png'} sessionHeaders = {'Accept': 'image/png'}
avatarImageFilename=baseDir+'/cache/avatars/'+actor.replace('/','#')+'.png'
elif avatarUrl.endswith('.jpg') or avatarUrl.endswith('.jpeg'): elif avatarUrl.endswith('.jpg') or avatarUrl.endswith('.jpeg'):
sessionHeaders = {'Accept': 'image/jpeg'} sessionHeaders = {'Accept': 'image/jpeg'}
avatarImageFilename=baseDir+'/cache/avatars/'+actor.replace('/','#')+'.jpg'
elif avatarUrl.endswith('.gif'): elif avatarUrl.endswith('.gif'):
sessionHeaders = {'Accept': 'image/gif'} sessionHeaders = {'Accept': 'image/gif'}
avatarImageFilename=baseDir+'/cache/avatars/'+actor.replace('/','#')+'.gif'
else: else:
return None return None
if not os.path.isfile(avatarImageFilename) or force:
try: try:
result=session.get(avatarUrl, headers=sessionHeaders, params=None) result=session.get(avatarUrl, headers=sessionHeaders, params=None)
with open(avatarImageFilename, 'wb') as f: with open(avatarImageFilename, 'wb') as f: