mirror of https://gitlab.com/bashrc2/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 \
|
'/statuses/' not in self.path and \
|
||||||
'/emoji/' not in self.path and \
|
'/emoji/' not in self.path and \
|
||||||
'/tags/' not in self.path and \
|
'/tags/' not in self.path and \
|
||||||
|
'/avatars/' not in self.path and \
|
||||||
'/icons/' not in self.path:
|
'/icons/' not in self.path:
|
||||||
divertToLoginScreen=True
|
divertToLoginScreen=True
|
||||||
if self.path.startswith('/users/'):
|
if self.path.startswith('/users/'):
|
||||||
|
@ -851,6 +852,28 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
return
|
return
|
||||||
self._404()
|
self._404()
|
||||||
return
|
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
|
# show avatar or background image
|
||||||
# Note that this comes before the busy flag to avoid conflicts
|
# Note that this comes before the busy flag to avoid conflicts
|
||||||
if '/users/' in self.path:
|
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:
|
def getPersonAvatarUrl(baseDir: str,personUrl: str,personCache: {}) -> str:
|
||||||
"""Returns the avatar url for the person
|
"""Returns the avatar url for the person
|
||||||
"""
|
"""
|
||||||
personJson = getPersonFromCache(baseDir,personUrl,personCache)
|
personJson = getPersonFromCache(baseDir,personUrl,personCache)
|
||||||
if personJson:
|
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.get('icon'):
|
||||||
if personJson['icon'].get('url'):
|
if personJson['icon'].get('url'):
|
||||||
return personJson['icon']['url']
|
return personJson['icon']['url']
|
||||||
|
|
Loading…
Reference in New Issue