Check if avatar image exists when entering person options

merge-requests/30/head
Bob Mottram 2021-02-14 13:01:52 +00:00
parent a3c3389741
commit 04e80de244
2 changed files with 27 additions and 0 deletions

View File

@ -13,6 +13,21 @@ from utils import saveJson
from utils import getFileCaseInsensitive from utils import getFileCaseInsensitive
def removePersonFromCache(baseDir: str, personUrl: str,
personCache: {}) -> bool:
"""Removes an actor from the cache
"""
cacheFilename = baseDir + '/cache/actors/' + \
personUrl.replace('/', '#')+'.json'
if os.path.isfile(cacheFilename):
try:
os.remove(cacheFilename)
except BaseException:
pass
if personCache.get(personUrl):
del personCache[personUrl]
def storePersonInCache(baseDir: str, personUrl: str, def storePersonInCache(baseDir: str, personUrl: str,
personJson: {}, personCache: {}, personJson: {}, personCache: {},
allowWriteToFile: bool) -> None: allowWriteToFile: bool) -> None:

View File

@ -20,6 +20,7 @@ import pyqrcode
# for saving images # for saving images
from hashlib import sha256 from hashlib import sha256
from hashlib import sha1 from hashlib import sha1
from siteactive import siteIsActive
from session import createSession from session import createSession
from webfinger import webfingerMeta from webfinger import webfingerMeta
from webfinger import webfingerNodeInfo from webfinger import webfingerNodeInfo
@ -228,6 +229,7 @@ from content import extractMediaInFormPOST
from content import saveMediaInFormPOST from content import saveMediaInFormPOST
from content import extractTextFieldsInPOST from content import extractTextFieldsInPOST
from media import removeMetaData from media import removeMetaData
from cache import removePersonFromCache
from cache import storePersonInCache from cache import storePersonInCache
from cache import getPersonFromCache from cache import getPersonFromCache
from httpsig import verifyPostHeaders from httpsig import verifyPostHeaders
@ -5488,6 +5490,16 @@ class PubServer(BaseHTTPRequestHandler):
PGPfingerprint = getPGPfingerprint(actorJson) PGPfingerprint = getPGPfingerprint(actorJson)
if actorJson.get('alsoKnownAs'): if actorJson.get('alsoKnownAs'):
alsoKnownAs = actorJson['alsoKnownAs'] alsoKnownAs = actorJson['alsoKnownAs']
# check if the avatar image exists and if not then update
# the actor cache
if optionsProfileUrl:
if self.server.domainFull not in optionsProfileUrl:
if not siteIsActive(optionsProfileUrl, 3):
removePersonFromCache(self.server.baseDir,
optionsActor,
self.server.personCache)
msg = htmlPersonOptions(self.server.defaultTimeline, msg = htmlPersonOptions(self.server.defaultTimeline,
self.server.cssCache, self.server.cssCache,
self.server.translate, self.server.translate,