diff --git a/announce.py b/announce.py index 81c5bf3d6..eec04fa13 100644 --- a/announce.py +++ b/announce.py @@ -88,8 +88,9 @@ def undoAnnounceCollectionEntry(recentPostsCache: {}, \ nickname=getNicknameFromActor(actor) cachedPostFilename= \ getCachedPostFilename(baseDir,nickname,domain,postJsonObject) - if os.path.isfile(cachedPostFilename): - os.remove(cachedPostFilename) + if cachedPostFilename: + if os.path.isfile(cachedPostFilename): + os.remove(cachedPostFilename) removePostFromCache(postJsonObject,recentPostsCache) if not postJsonObject.get('type'): @@ -144,8 +145,9 @@ def updateAnnounceCollection(recentPostsCache: {}, \ nickname=getNicknameFromActor(actor) cachedPostFilename= \ getCachedPostFilename(baseDir,nickname,domain,postJsonObject) - if os.path.isfile(cachedPostFilename): - os.remove(cachedPostFilename) + if cachedPostFilename: + if os.path.isfile(cachedPostFilename): + os.remove(cachedPostFilename) removePostFromCache(postJsonObject,recentPostsCache) if not postJsonObject.get('object'): diff --git a/bookmarks.py b/bookmarks.py index 0c365250e..29483df8c 100644 --- a/bookmarks.py +++ b/bookmarks.py @@ -37,8 +37,9 @@ def undoBookmarksCollectionEntry(recentPostsCache: {}, \ nickname=getNicknameFromActor(actor) cachedPostFilename= \ getCachedPostFilename(baseDir,nickname,domain,postJsonObject) - if os.path.isfile(cachedPostFilename): - os.remove(cachedPostFilename) + if cachedPostFilename: + if os.path.isfile(cachedPostFilename): + os.remove(cachedPostFilename) removePostFromCache(postJsonObject,recentPostsCache) if not postJsonObject.get('type'): @@ -143,8 +144,9 @@ def updateBookmarksCollection(recentPostsCache: {}, \ nickname=getNicknameFromActor(actor) cachedPostFilename= \ getCachedPostFilename(baseDir,nickname,domain,postJsonObject) - if os.path.isfile(cachedPostFilename): - os.remove(cachedPostFilename) + if cachedPostFilename: + if os.path.isfile(cachedPostFilename): + os.remove(cachedPostFilename) removePostFromCache(postJsonObject,recentPostsCache) if not postJsonObject.get('object'): diff --git a/like.py b/like.py index b93ae4113..e834b0eb4 100644 --- a/like.py +++ b/like.py @@ -35,8 +35,9 @@ def undoLikesCollectionEntry(recentPostsCache: {}, \ nickname=getNicknameFromActor(actor) cachedPostFilename= \ getCachedPostFilename(baseDir,nickname,domain,postJsonObject) - if os.path.isfile(cachedPostFilename): - os.remove(cachedPostFilename) + if cachedPostFilename: + if os.path.isfile(cachedPostFilename): + os.remove(cachedPostFilename) removePostFromCache(postJsonObject,recentPostsCache) if not postJsonObject.get('type'): @@ -117,8 +118,9 @@ def updateLikesCollection(recentPostsCache: {}, \ nickname=getNicknameFromActor(actor) cachedPostFilename= \ getCachedPostFilename(baseDir,nickname,domain,postJsonObject) - if os.path.isfile(cachedPostFilename): - os.remove(cachedPostFilename) + if cachedPostFilename: + if os.path.isfile(cachedPostFilename): + os.remove(cachedPostFilename) removePostFromCache(postJsonObject,recentPostsCache) if not postJsonObject.get('object'): diff --git a/utils.py b/utils.py index 094b82311..8be29b6fd 100644 --- a/utils.py +++ b/utils.py @@ -447,8 +447,15 @@ def getCachedPostFilename(baseDir: str,nickname: str,domain: str, \ postJsonObject: {}) -> str: """Returns the html cache filename for the given post """ + cachedPostDir=getCachedPostDirectory(baseDir,nickname,domain) + if not os.path.isdir(cachedPostDir): + print('ERROR: invalid html cache directory '+cachedPostDir) + return None + if '@' not in cachedPostDir: + print('ERROR: invalid html cache directory '+cachedPostDir) + return None cachedPostFilename= \ - getCachedPostDirectory(baseDir,nickname,domain)+ \ + cachedPostDir+ \ '/'+postJsonObject['id'].replace('/activity','') print('CACHE: 1 '+nickname+' '+domain+' '+cachedPostFilename) if '#' in cachedPostFilename: diff --git a/webinterface.py b/webinterface.py index 76bdfaf42..8f66d6f5a 100644 --- a/webinterface.py +++ b/webinterface.py @@ -1948,6 +1948,9 @@ def loadIndividualPostAsHtmlFromCache(baseDir: str,nickname: str,domain: str, \ cachedPostFilename=getCachedPostFilename(baseDir,nickname,domain,postJsonObject) postHtml='' + if not cachedPostFilename: + return postHtml + if not os.path.isfile(cachedPostFilename): return postHtml