From 4d849f33a8880a21421e255296bf4fd488dd2e59 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Thu, 10 Jun 2021 10:37:44 +0100 Subject: [PATCH] Change paths for avatars and backgrounds to be similar to Mastodon icon/image --- daemon.py | 16 +++++++++++++--- person.py | 8 ++++++-- utils.py | 3 ++- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/daemon.py b/daemon.py index 7d3bc702e..dbce28c7c 100644 --- a/daemon.py +++ b/daemon.py @@ -1267,7 +1267,9 @@ class PubServer(BaseHTTPRequestHandler): self.authorizedNickname = None notAuthPaths = ( - '/icons/', '/avatars/', '/favicon.ico', '/newswire.xml', + '/icons/', '/avatars/', + '/accounts/avatars/', '/accounts/headers/', + '/favicon.ico', '/newswire.xml', '/newswire_favicon.ico', '/categories.xml' ) for notAuthStr in notAuthPaths: @@ -9902,6 +9904,7 @@ class PubServer(BaseHTTPRequestHandler): '/emoji/' not in path and \ '/tags/' not in path and \ '/avatars/' not in path and \ + '/headers/' not in path and \ '/fonts/' not in path and \ '/icons/' not in path: divertToLoginScreen = True @@ -10199,10 +10202,17 @@ class PubServer(BaseHTTPRequestHandler): """Shows an avatar or banner or profile background image """ if '/users/' not in path: - return False + if '/accounts/avatars/' not in path: + if '/accounts/headers/' not in path: + return False if not pathIsImage(path): return False - avatarStr = path.split('/users/')[1] + if '/accounts/avatars/' in path: + avatarStr = path.split('/accounts/avatars/')[1] + elif '/accounts/headers/' in path: + avatarStr = path.split('/accounts/headers/')[1] + else: + avatarStr = path.split('/users/')[1] if not ('/' in avatarStr and '.temp.' not in path): return False avatarNickname = avatarStr.split('/')[0] diff --git a/person.py b/person.py index 9dea15d95..69f639d70 100644 --- a/person.py +++ b/person.py @@ -162,13 +162,17 @@ def randomizeActorImages(personJson: {}) -> None: # NOTE: these files don't need to have cryptographically # secure names randStr = str(randint(10000000000000, 99999999999999)) # nosec + baseUrl = personId.split('/users/')[0] + nickname = personJson['preferredUsername'] personJson['icon']['url'] = \ - personId + '/avatar' + randStr + '.' + existingExtension + baseUrl + '/accounts/avatars/' + nickname + \ + '/avatar' + randStr + '.' + existingExtension lastPartOfFilename = personJson['image']['url'].split('/')[-1] existingExtension = lastPartOfFilename.split('.')[1] randStr = str(randint(10000000000000, 99999999999999)) # nosec personJson['image']['url'] = \ - personId + '/image' + randStr + '.' + existingExtension + baseUrl + '/accounts/headers/' + nickname + \ + '/image' + randStr + '.' + existingExtension def getDefaultPersonContext() -> str: diff --git a/utils.py b/utils.py index 0612247c1..ce35bab49 100644 --- a/utils.py +++ b/utils.py @@ -1434,7 +1434,8 @@ def _isReservedName(nickname: str) -> bool: 'activity', 'undo', 'pinned', 'reply', 'replies', 'question', 'like', 'likes', 'users', 'statuses', 'tags', - 'accounts', 'channels', 'profile', 'u', + 'accounts', 'headers', + 'channels', 'profile', 'u', 'updates', 'repeat', 'announce', 'shares', 'fonts', 'icons', 'avatars', 'welcome', 'helpimages',