diff --git a/content.py b/content.py index 28e3f430d..24811e34a 100644 --- a/content.py +++ b/content.py @@ -14,7 +14,7 @@ from shutil import copyfile from utils import dangerousSVG from utils import removeDomainPort from utils import isValidLanguage -from utils import getImageExtensions +from utils import get_image_extensions from utils import loadJson from utils import saveJson from utils import fileLastModified @@ -1024,7 +1024,7 @@ def saveMediaInFormPOST(mediaBytes, debug: bool, if not mediaBytes: if filenameBase: # remove any existing files - extensionTypes = getImageExtensions() + extensionTypes = get_image_extensions() for ex in extensionTypes: possibleOtherFormat = filenameBase + '.' + ex if os.path.isfile(possibleOtherFormat): @@ -1099,7 +1099,7 @@ def saveMediaInFormPOST(mediaBytes, debug: bool, # remove any existing image files with a different format if detectedExtension != 'zip': - extensionTypes = getImageExtensions() + extensionTypes = get_image_extensions() for ex in extensionTypes: if ex == detectedExtension: continue diff --git a/daemon.py b/daemon.py index 7e2ffea49..2828085d8 100644 --- a/daemon.py +++ b/daemon.py @@ -276,7 +276,7 @@ from utils import get_full_domain from utils import removeHtml from utils import is_editor from utils import is_artist -from utils import getImageExtensions +from utils import get_image_extensions from utils import mediaFileMimeType from utils import getCSS from utils import firstParagraphFromString @@ -12647,7 +12647,7 @@ class PubServer(BaseHTTPRequestHandler): base_dir: str, GETstartTime) -> bool: """Show a background image """ - imageExtensions = getImageExtensions() + imageExtensions = get_image_extensions() for ext in imageExtensions: for bg in ('follow', 'options', 'login', 'welcome'): # follow screen background image @@ -12696,7 +12696,7 @@ class PubServer(BaseHTTPRequestHandler): """If a background image is missing after searching for a handle then substitute this image """ - imageExtensions = getImageExtensions() + imageExtensions = get_image_extensions() for ext in imageExtensions: bgFilename = \ base_dir + '/theme/' + theme_name + '/image.' + ext @@ -12823,7 +12823,7 @@ class PubServer(BaseHTTPRequestHandler): if not os.path.isfile(avatarFilename): originalExt = avatarFileExt originalAvatarFile = avatarFile - altExt = getImageExtensions() + altExt = get_image_extensions() altFound = False for alt in altExt: if alt == originalExt: diff --git a/media.py b/media.py index 64dad4906..96f5cb100 100644 --- a/media.py +++ b/media.py @@ -17,7 +17,7 @@ from hashlib import sha1 from auth import createPassword from utils import get_base_content_from_post from utils import get_full_domain -from utils import getImageExtensions +from utils import get_image_extensions from utils import get_video_extensions from utils import get_audio_extensions from utils import getMediaExtensions @@ -246,7 +246,7 @@ def getAttachmentMediaType(filename: str) -> str: image, video or audio """ mediaType = None - imageTypes = getImageExtensions() + imageTypes = get_image_extensions() for mType in imageTypes: if filename.endswith('.' + mType): return 'image' diff --git a/person.py b/person.py index aad9a63c6..c720f77d6 100644 --- a/person.py +++ b/person.py @@ -53,7 +53,7 @@ from utils import get_config_param from utils import refresh_newswire from utils import getProtocolPrefixes from utils import has_users_path -from utils import getImageExtensions +from utils import get_image_extensions from utils import isImageFile from utils import acct_dir from utils import get_user_paths @@ -1619,7 +1619,7 @@ def getPersonAvatarUrl(base_dir: str, personUrl: str, person_cache: {}, actorStr = personJson['id'].replace('/', '-') avatarImagePath = base_dir + '/cache/avatars/' + actorStr - imageExtension = getImageExtensions() + imageExtension = get_image_extensions() for ext in imageExtension: imFilename = avatarImagePath + '.' + ext imPath = '/avatars/' + actorStr + '.' + ext diff --git a/shares.py b/shares.py index 037348b79..3ffa51fe5 100644 --- a/shares.py +++ b/shares.py @@ -30,7 +30,7 @@ from utils import get_full_domain from utils import validNickname from utils import loadJson from utils import saveJson -from utils import getImageExtensions +from utils import get_image_extensions from utils import removeDomainPort from utils import isAccountDir from utils import acct_dir @@ -142,7 +142,7 @@ def removeSharedItem(base_dir: str, nickname: str, domain: str, # remove any image for the item itemIDfile = base_dir + '/sharefiles/' + nickname + '/' + itemID if sharesJson[itemID]['imageUrl']: - formats = getImageExtensions() + formats = get_image_extensions() for ext in formats: if sharesJson[itemID]['imageUrl'].endswith('.' + ext): if os.path.isfile(itemIDfile + '.' + ext): @@ -339,7 +339,7 @@ def addShare(base_dir: str, if not imageFilename: sharesImageFilename = \ acct_dir(base_dir, nickname, domain) + '/upload' - formats = getImageExtensions() + formats = get_image_extensions() for ext in formats: if os.path.isfile(sharesImageFilename + '.' + ext): imageFilename = sharesImageFilename + '.' + ext @@ -355,7 +355,7 @@ def addShare(base_dir: str, if not os.path.isdir(base_dir + '/sharefiles/' + nickname): os.mkdir(base_dir + '/sharefiles/' + nickname) itemIDfile = base_dir + '/sharefiles/' + nickname + '/' + itemID - formats = getImageExtensions() + formats = get_image_extensions() for ext in formats: if not imageFilename.endswith('.' + ext): continue @@ -435,7 +435,7 @@ def _expireSharesForAccount(base_dir: str, nickname: str, domain: str, del sharesJson[itemID] # remove any associated images itemIDfile = base_dir + '/sharefiles/' + nickname + '/' + itemID - formats = getImageExtensions() + formats = get_image_extensions() for ext in formats: if os.path.isfile(itemIDfile + '.' + ext): try: diff --git a/theme.py b/theme.py index d7bf359a2..4a265e19d 100644 --- a/theme.py +++ b/theme.py @@ -11,7 +11,7 @@ import os from utils import isAccountDir from utils import loadJson from utils import saveJson -from utils import getImageExtensions +from utils import get_image_extensions from utils import copytree from utils import acct_dir from utils import dangerousSVG @@ -679,7 +679,7 @@ def _setThemeImages(base_dir: str, name: str) -> None: backgroundNames = ('login', 'shares', 'delete', 'follow', 'options', 'block', 'search', 'calendar', 'welcome') - extensions = getImageExtensions() + extensions = get_image_extensions() for subdir, dirs, files in os.walk(base_dir + '/accounts'): for acct in dirs: diff --git a/utils.py b/utils.py index 51dc3e41c..ede0292dc 100644 --- a/utils.py +++ b/utils.py @@ -354,7 +354,7 @@ def get_audio_extensions() -> []: return ('mp3', 'ogg', 'flac') -def getImageExtensions() -> []: +def get_image_extensions() -> []: """Returns a list of the possible image file extensions """ return ('png', 'jpg', 'jpeg', 'gif', 'webp', 'avif', 'svg', 'ico') @@ -399,7 +399,7 @@ def getImageExtensionFromMimeType(contentType: str) -> str: def getMediaExtensions() -> []: """Returns a list of the possible media file extensions """ - return getImageExtensions() + \ + return get_image_extensions() + \ get_video_extensions() + get_audio_extensions() @@ -407,7 +407,7 @@ def getImageFormats() -> str: """Returns a string of permissable image formats used when selecting an image for a new post """ - imageExt = getImageExtensions() + imageExt = get_image_extensions() imageFormats = '' for ext in imageExt: @@ -420,7 +420,7 @@ def getImageFormats() -> str: def isImageFile(filename: str) -> bool: """Is the given filename an image? """ - for ext in getImageExtensions(): + for ext in get_image_extensions(): if filename.endswith('.' + ext): return True return False @@ -642,7 +642,7 @@ def removeAvatarFromCache(base_dir: str, actorStr: str) -> None: """Removes any existing avatar entries from the cache This avoids duplicate entries with differing extensions """ - avatarFilenameExtensions = getImageExtensions() + avatarFilenameExtensions = get_image_extensions() for extension in avatarFilenameExtensions: avatarFilename = \ base_dir + '/cache/avatars/' + actorStr + '.' + extension diff --git a/webapp_utils.py b/webapp_utils.py index 36800be74..d2663e185 100644 --- a/webapp_utils.py +++ b/webapp_utils.py @@ -22,7 +22,7 @@ from utils import getNicknameFromActor from utils import isfloat from utils import get_audio_extensions from utils import get_video_extensions -from utils import getImageExtensions +from utils import get_image_extensions from utils import local_actor_url from cache import storePersonInCache from content import addHtmlTags @@ -471,7 +471,7 @@ def _getImageFile(base_dir: str, name: str, directory: str, """ returns the filenames for an image with the given name """ - bannerExtensions = getImageExtensions() + bannerExtensions = get_image_extensions() bannerFile = '' bannerFilename = '' for ext in bannerExtensions: @@ -943,7 +943,7 @@ def _isImageMimeType(mimeType: str) -> bool: return True if not mimeType.startswith('image/'): return False - extensions = getImageExtensions() + extensions = get_image_extensions() ext = mimeType.split('/')[1] if ext in extensions: return True diff --git a/webapp_welcome_profile.py b/webapp_welcome_profile.py index 71ae29c81..00e27315f 100644 --- a/webapp_welcome_profile.py +++ b/webapp_welcome_profile.py @@ -12,7 +12,7 @@ from shutil import copyfile from utils import removeHtml from utils import loadJson from utils import get_config_param -from utils import getImageExtensions +from utils import get_image_extensions from utils import getImageFormats from utils import acct_dir from utils import local_actor_url @@ -70,7 +70,7 @@ def htmlWelcomeProfile(base_dir: str, nickname: str, domain: str, profileForm = htmlHeaderWithExternalStyle(cssFilename, instanceTitle, None) # get the url of the avatar - for ext in getImageExtensions(): + for ext in get_image_extensions(): avatarFilename = \ acct_dir(base_dir, nickname, domain) + '/avatar.' + ext if os.path.isfile(avatarFilename):