forked from indymedia/epicyon
Clearing avatar images from cache before storing updated ones
parent
a5251ba561
commit
972727cc8b
13
daemon.py
13
daemon.py
|
@ -147,6 +147,7 @@ from shares import outboxUndoShareUpload
|
|||
from shares import addShare
|
||||
from shares import removeShare
|
||||
from shares import expireShares
|
||||
from utils import removeAvatarFromCache
|
||||
from utils import locatePost
|
||||
from utils import getCachedPostFilename
|
||||
from utils import removePostFromCache
|
||||
|
@ -4308,17 +4309,7 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
actorJson['id'],actorJson, \
|
||||
self.server.personCache)
|
||||
# clear any cached images for this actor
|
||||
avatarCacheFilename= \
|
||||
self.server.baseDir+'/cache/avatars/'+ \
|
||||
actorJson['id'].replace('/','#')
|
||||
if os.path.isfile(avatarCacheFilename+'.png'):
|
||||
os.remove(avatarCacheFilename+'.png')
|
||||
if os.path.isfile(avatarCacheFilename+'.jpg'):
|
||||
os.remove(avatarCacheFilename+'.jpg')
|
||||
if os.path.isfile(avatarCacheFilename+'.gif'):
|
||||
os.remove(avatarCacheFilename+'.gif')
|
||||
if os.path.isfile(avatarCacheFilename+'.webp'):
|
||||
os.remove(avatarCacheFilename+'.webp')
|
||||
removeAvatarFromCache(self.server.baseDir,actorJson['id'].replace('/','-'))
|
||||
# save the actor to the cache
|
||||
actorCacheFilename= \
|
||||
self.server.baseDir+'/cache/actors/'+ \
|
||||
|
|
7
inbox.py
7
inbox.py
|
@ -12,6 +12,7 @@ import datetime
|
|||
import time
|
||||
import json
|
||||
from shutil import copyfile
|
||||
from utils import removeAvatarFromCache
|
||||
from utils import isPublicPost
|
||||
from utils import getCachedPostFilename
|
||||
from utils import removePostFromCache
|
||||
|
@ -775,11 +776,7 @@ def personReceiveUpdate(baseDir: str, \
|
|||
# remove avatar if it exists so that it will be refreshed later
|
||||
# when a timeline is constructed
|
||||
actorStr=personJson['id'].replace('/','-')
|
||||
avatarFilenameExtensions=('png','jpg','gif','webp')
|
||||
for extension in avatarFilenameExtensions:
|
||||
avatarFilename=baseDir+'/cache/avatars/'+actorStr+'.'+extension
|
||||
if os.path.isfile(avatarFilename):
|
||||
os.remove(avatarFilename)
|
||||
removeAvatarFromCache(baseDir,actorStr)
|
||||
return True
|
||||
|
||||
def receiveUpdateToQuestion(recentPostsCache: {},messageJson: {}, \
|
||||
|
|
10
utils.py
10
utils.py
|
@ -12,6 +12,16 @@ import shutil
|
|||
import datetime
|
||||
import json
|
||||
|
||||
def removeAvatarFromCache(baseDir: str,actorStr: str) -> None:
|
||||
"""Removes any existing avatar entries from the cache
|
||||
This avoids duplicate entries with differing extensions
|
||||
"""
|
||||
avatarFilenameExtensions=('png','jpg','gif','webp')
|
||||
for extension in avatarFilenameExtensions:
|
||||
avatarFilename=baseDir+'/cache/avatars/'+actorStr+'.'+extension
|
||||
if os.path.isfile(avatarFilename):
|
||||
os.remove(avatarFilename)
|
||||
|
||||
def saveJson(jsonObject: {},filename: str) -> bool:
|
||||
"""Saves json to a file
|
||||
"""
|
||||
|
|
|
@ -68,7 +68,8 @@ def updateAvatarImageCache(session,baseDir: str,httpPrefix: str,actor: str,avata
|
|||
"""
|
||||
if not avatarUrl:
|
||||
return None
|
||||
avatarImagePath=baseDir+'/cache/avatars/'+actor.replace('/','-')
|
||||
actorStr=actor.replace('/','-')
|
||||
avatarImagePath=baseDir+'/cache/avatars/'+actorStr
|
||||
if avatarUrl.endswith('.png') or '.png?' in avatarUrl:
|
||||
sessionHeaders = {'Accept': 'image/png'}
|
||||
avatarImageFilename=avatarImagePath+'.png'
|
||||
|
|
Loading…
Reference in New Issue