From 04e80de2442a705e6c5a0ae5c13c0d5864200b64 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 14 Feb 2021 13:01:52 +0000 Subject: [PATCH] Check if avatar image exists when entering person options --- cache.py | 15 +++++++++++++++ daemon.py | 12 ++++++++++++ 2 files changed, 27 insertions(+) diff --git a/cache.py b/cache.py index 0505ef543..f711df01b 100644 --- a/cache.py +++ b/cache.py @@ -13,6 +13,21 @@ from utils import saveJson 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, personJson: {}, personCache: {}, allowWriteToFile: bool) -> None: diff --git a/daemon.py b/daemon.py index 59d2261d2..335b13f96 100644 --- a/daemon.py +++ b/daemon.py @@ -20,6 +20,7 @@ import pyqrcode # for saving images from hashlib import sha256 from hashlib import sha1 +from siteactive import siteIsActive from session import createSession from webfinger import webfingerMeta from webfinger import webfingerNodeInfo @@ -228,6 +229,7 @@ from content import extractMediaInFormPOST from content import saveMediaInFormPOST from content import extractTextFieldsInPOST from media import removeMetaData +from cache import removePersonFromCache from cache import storePersonInCache from cache import getPersonFromCache from httpsig import verifyPostHeaders @@ -5488,6 +5490,16 @@ class PubServer(BaseHTTPRequestHandler): PGPfingerprint = getPGPfingerprint(actorJson) if actorJson.get('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, self.server.cssCache, self.server.translate,