Case insensitive avatar image search

main
Bob Mottram 2020-05-04 19:24:30 +01:00
parent 82312175a8
commit a9206ee855
2 changed files with 14 additions and 1 deletions

View File

@ -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

View File

@ -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'):