diff --git a/utils.py b/utils.py index 2a68a15e4..848959542 100644 --- a/utils.py +++ b/utils.py @@ -19,6 +19,26 @@ from calendar import monthrange from followingCalendar import addPersonToCalendar +def getImageExtensions() -> []: + """Returns a list of the possible image file extensions + """ + return ('png', 'jpg', 'jpeg', 'gif', 'webp', 'avif') + + +def getImageFormats() -> str: + """Returns a string of permissable image formats + used when selecting an image for a new post + """ + imageExt = getImageExtensions() + + imageFormats = '' + for ext in imageExt: + if imageFormats: + imageFormats += ', ' + imageFormats += '.' + ext + return imageFormats + + def removeHtml(content: str) -> str: """Removes html links from the given content. Used to ensure that profile descriptions don't contain dubious content diff --git a/webapp_profile.py b/webapp_profile.py index b84169b72..1e5d2acfd 100644 --- a/webapp_profile.py +++ b/webapp_profile.py @@ -14,6 +14,7 @@ from utils import isSystemAccount from utils import removeHtml from utils import loadJson from utils import getConfigParam +from utils import getImageFormats from skills import getSkills from theme import getThemesList from person import personBoxJson @@ -851,7 +852,7 @@ def htmlEditProfile(cssCache: {}, translate: {}, baseDir: str, path: str, defaultTimeline: str) -> str: """Shows the edit profile screen """ - imageFormats = '.png, .jpg, .jpeg, .gif, .webp, .avif' + imageFormats = getImageFormats() path = path.replace('/inbox', '').replace('/outbox', '') path = path.replace('/shares', '') nickname = getNicknameFromActor(path) diff --git a/webapp_utils.py b/webapp_utils.py index 6a18f06c4..9736aaaa2 100644 --- a/webapp_utils.py +++ b/webapp_utils.py @@ -9,6 +9,7 @@ __status__ = "Production" import os from collections import OrderedDict from session import getJson +from utils import getImageExtensions from utils import getProtocolPrefixes from utils import loadJson from utils import getCachedPostFilename @@ -248,12 +249,6 @@ def updateAvatarImageCache(session, baseDir: str, httpPrefix: str, return avatarImageFilename.replace(baseDir + '/cache', '') -def getImageExtensions() -> []: - """Returns a list of the possible image file extensions - """ - return ('png', 'jpg', 'jpeg', 'gif', 'webp', 'avif') - - def getPersonAvatarUrl(baseDir: str, personUrl: str, personCache: {}, allowDownloads: bool) -> str: """Returns the avatar url for the person