From a9206ee8558df1cd68c9dff229217689e8775d8d Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 4 May 2020 19:24:30 +0100 Subject: [PATCH] Case insensitive avatar image search --- utils.py | 11 +++++++++++ webinterface.py | 4 +++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/utils.py b/utils.py index 44733fbef..1538557a3 100644 --- a/utils.py +++ b/utils.py @@ -769,3 +769,14 @@ def searchBoxPosts(baseDir: str, nickname: str, domain: str, if len(res) >= maxResults: return res return res + + +def getFileCaseInsensitive(filename: str) -> str: + """Returns a case specific filename given a case insensitive version of it + """ + directory, filename = os.path.split(filename) + directory, filename = (directory or '.'), filename.lower() + for f in os.listdir(directory): + newFilename = os.path.join(directory, f) + if os.path.isfile(newFilename) and f.lower() == filename: + return newFilename diff --git a/webinterface.py b/webinterface.py index 957d19b60..c5b80c498 100644 --- a/webinterface.py +++ b/webinterface.py @@ -24,6 +24,7 @@ from ssb import getSSBAddress from tox import getToxAddress from matrix import getMatrixAddress from donate import getDonationUrl +from utils import getFileCaseInsensitive from utils import searchBoxPosts from utils import isBlogPost from utils import updateRecentPostsCache @@ -254,7 +255,8 @@ def getPersonAvatarUrl(baseDir: str, personUrl: str, personCache: {}) -> str: return None # get from locally stored image actorStr = personJson['id'].replace('/', '-') - avatarImagePath = baseDir + '/cache/avatars/' + actorStr + avatarImagePath = \ + getFileCaseInsensitive(baseDir + '/cache/avatars/' + actorStr if os.path.isfile(avatarImagePath + '.png'): return '/avatars/' + actorStr + '.png' elif os.path.isfile(avatarImagePath + '.jpg'):