Move image format functions to utils

merge-requests/30/head
Bob Mottram 2020-11-21 11:21:05 +00:00
parent 4f865d57e2
commit 050c87d0e4
3 changed files with 23 additions and 7 deletions

View File

@ -19,6 +19,26 @@ from calendar import monthrange
from followingCalendar import addPersonToCalendar 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: def removeHtml(content: str) -> str:
"""Removes html links from the given content. """Removes html links from the given content.
Used to ensure that profile descriptions don't contain dubious content Used to ensure that profile descriptions don't contain dubious content

View File

@ -14,6 +14,7 @@ from utils import isSystemAccount
from utils import removeHtml from utils import removeHtml
from utils import loadJson from utils import loadJson
from utils import getConfigParam from utils import getConfigParam
from utils import getImageFormats
from skills import getSkills from skills import getSkills
from theme import getThemesList from theme import getThemesList
from person import personBoxJson from person import personBoxJson
@ -851,7 +852,7 @@ def htmlEditProfile(cssCache: {}, translate: {}, baseDir: str, path: str,
defaultTimeline: str) -> str: defaultTimeline: str) -> str:
"""Shows the edit profile screen """Shows the edit profile screen
""" """
imageFormats = '.png, .jpg, .jpeg, .gif, .webp, .avif' imageFormats = getImageFormats()
path = path.replace('/inbox', '').replace('/outbox', '') path = path.replace('/inbox', '').replace('/outbox', '')
path = path.replace('/shares', '') path = path.replace('/shares', '')
nickname = getNicknameFromActor(path) nickname = getNicknameFromActor(path)

View File

@ -9,6 +9,7 @@ __status__ = "Production"
import os import os
from collections import OrderedDict from collections import OrderedDict
from session import getJson from session import getJson
from utils import getImageExtensions
from utils import getProtocolPrefixes from utils import getProtocolPrefixes
from utils import loadJson from utils import loadJson
from utils import getCachedPostFilename from utils import getCachedPostFilename
@ -248,12 +249,6 @@ def updateAvatarImageCache(session, baseDir: str, httpPrefix: str,
return avatarImageFilename.replace(baseDir + '/cache', '') 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: {}, def getPersonAvatarUrl(baseDir: str, personUrl: str, personCache: {},
allowDownloads: bool) -> str: allowDownloads: bool) -> str:
"""Returns the avatar url for the person """Returns the avatar url for the person