forked from indymedia/epicyon
Reading cached avatars
parent
2975601956
commit
33989bb08b
23
daemon.py
23
daemon.py
|
@ -674,6 +674,7 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
'/statuses/' not in self.path and \
|
||||
'/emoji/' not in self.path and \
|
||||
'/tags/' not in self.path and \
|
||||
'/avatars/' not in self.path and \
|
||||
'/icons/' not in self.path:
|
||||
divertToLoginScreen=True
|
||||
if self.path.startswith('/users/'):
|
||||
|
@ -851,6 +852,28 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
return
|
||||
self._404()
|
||||
return
|
||||
# cached avatar images
|
||||
# Note that this comes before the busy flag to avoid conflicts
|
||||
if self.path.startswith('/avatars/'):
|
||||
mediaFilename= \
|
||||
self.server.baseDir+'/cache/'+self.path
|
||||
if os.path.isfile(mediaFilename):
|
||||
with open(mediaFilename, 'rb') as avFile:
|
||||
mediaBinary = avFile.read()
|
||||
if mediaFilename.endswith('.png'):
|
||||
self._set_headers('image/png',len(mediaBinary),cookie)
|
||||
elif mediaFilename.endswith('.jpg'):
|
||||
self._set_headers('image/jpeg',len(mediaBinary),cookie)
|
||||
elif mediaFilename.endswith('.gof'):
|
||||
self._set_headers('image/gif',len(mediaBinary),cookie)
|
||||
else:
|
||||
self._404()
|
||||
return
|
||||
self.wfile.write(mediaBinary)
|
||||
self.wfile.flush()
|
||||
return
|
||||
self._404()
|
||||
return
|
||||
# show avatar or background image
|
||||
# Note that this comes before the busy flag to avoid conflicts
|
||||
if '/users/' in self.path:
|
||||
|
|
|
@ -79,8 +79,19 @@ def updateAvatarImageCache(session,baseDir: str,httpPrefix: str,actor: str,avata
|
|||
def getPersonAvatarUrl(baseDir: str,personUrl: str,personCache: {}) -> str:
|
||||
"""Returns the avatar url for the person
|
||||
"""
|
||||
personJson = getPersonFromCache(baseDir,personUrl,personCache)
|
||||
personJson = getPersonFromCache(baseDir,personUrl,personCache)
|
||||
if personJson:
|
||||
actorStr=personJson['actor'].replace('/','#')
|
||||
avatarImageFilename=baseDir+'/cache/avatars/'+actorStr+'.png'
|
||||
if os.path.isfile(avatarImageFilename):
|
||||
return '/avatars/'+actorStr+'.png'
|
||||
avatarImageFilename=baseDir+'/cache/avatars/'+actorStr+'.jpg'
|
||||
if os.path.isfile(avatarImageFilename):
|
||||
return '/avatars/'+actorStr+'.jpg'
|
||||
avatarImageFilename=baseDir+'/cache/avatars/'+actorStr+'.gif'
|
||||
if os.path.isfile(avatarImageFilename):
|
||||
return '/avatars/'+actorStr+'.gif'
|
||||
|
||||
if personJson.get('icon'):
|
||||
if personJson['icon'].get('url'):
|
||||
return personJson['icon']['url']
|
||||
|
|
Loading…
Reference in New Issue