Tidying of mime types

merge-requests/30/head
Bob Mottram 2021-08-03 10:09:04 +01:00
parent b30d256faa
commit beb451baf7
3 changed files with 36 additions and 33 deletions

View File

@ -951,6 +951,7 @@ def saveMediaInFormPOST(mediaBytes, debug: bool,
'ogv': 'video/ogv', 'ogv': 'video/ogv',
'mp3': 'audio/mpeg', 'mp3': 'audio/mpeg',
'ogg': 'audio/ogg', 'ogg': 'audio/ogg',
'flac': 'audio/flac',
'zip': 'application/zip' 'zip': 'application/zip'
} }
detectedExtension = None detectedExtension = None

View File

@ -297,6 +297,18 @@ def isArtist(baseDir: str, nickname: str) -> bool:
return False return False
def getVideoExtensions() -> []:
"""Returns a list of the possible video file extensions
"""
return ('mp4', 'webm', 'ogv')
def getAudioExtensions() -> []:
"""Returns a list of the possible audio file extensions
"""
return ('mp3', 'ogg', 'flac')
def getImageExtensions() -> []: def getImageExtensions() -> []:
"""Returns a list of the possible image file extensions """Returns a list of the possible image file extensions
""" """
@ -337,18 +349,6 @@ def getImageExtensionFromMimeType(contentType: str) -> str:
return 'png' return 'png'
def getVideoExtensions() -> []:
"""Returns a list of the possible video file extensions
"""
return ('mp4', 'webm', 'ogv')
def getAudioExtensions() -> []:
"""Returns a list of the possible audio file extensions
"""
return ('mp3', 'ogg')
def getMediaExtensions() -> []: def getMediaExtensions() -> []:
"""Returns a list of the possible media file extensions """Returns a list of the possible media file extensions
""" """
@ -2216,6 +2216,7 @@ def mediaFileMimeType(filename: str) -> str:
'avif': 'image/avif', 'avif': 'image/avif',
'mp3': 'audio/mpeg', 'mp3': 'audio/mpeg',
'ogg': 'audio/ogg', 'ogg': 'audio/ogg',
'flac': 'audio/flac',
'mp4': 'video/mp4', 'mp4': 'video/mp4',
'ogv': 'video/ogv' 'ogv': 'video/ogv'
} }

View File

@ -12,7 +12,6 @@ from collections import OrderedDict
from session import getJson from session import getJson
from utils import isAccountDir from utils import isAccountDir
from utils import removeHtml from utils import removeHtml
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
@ -20,6 +19,9 @@ from utils import getConfigParam
from utils import acctDir from utils import acctDir
from utils import getNicknameFromActor from utils import getNicknameFromActor
from utils import isfloat from utils import isfloat
from utils import getAudioExtensions
from utils import getVideoExtensions
from utils import getImageExtensions
from cache import storePersonInCache from cache import storePersonInCache
from content import addHtmlTags from content import addHtmlTags
from content import replaceEmojiFromTags from content import replaceEmojiFromTags
@ -793,15 +795,13 @@ def addEmojiToDisplayName(baseDir: str, httpPrefix: str,
def _isImageMimeType(mimeType: str) -> bool: def _isImageMimeType(mimeType: str) -> bool:
"""Is the given mime type an image? """Is the given mime type an image?
""" """
imageMimeTypes = ( extensions = getImageExtensions()
'image/png', if mimeType == 'image/svg+xml':
'image/jpeg', return True
'image/webp', if not mimeType.startswith('image/'):
'image/avif', return False
'image/svg+xml', ext = mimeType.split('/')[1]
'image/gif' if ext in extensions:
)
if mimeType in imageMimeTypes:
return True return True
return False return False
@ -809,12 +809,11 @@ def _isImageMimeType(mimeType: str) -> bool:
def _isVideoMimeType(mimeType: str) -> bool: def _isVideoMimeType(mimeType: str) -> bool:
"""Is the given mime type a video? """Is the given mime type a video?
""" """
videoMimeTypes = ( extensions = getVideoExtensions()
'video/mp4', if not mimeType.startswith('video/'):
'video/webm', return False
'video/ogv' ext = mimeType.split('/')[1]
) if ext in extensions:
if mimeType in videoMimeTypes:
return True return True
return False return False
@ -822,11 +821,13 @@ def _isVideoMimeType(mimeType: str) -> bool:
def _isAudioMimeType(mimeType: str) -> bool: def _isAudioMimeType(mimeType: str) -> bool:
"""Is the given mime type an audio file? """Is the given mime type an audio file?
""" """
audioMimeTypes = ( extensions = getAudioExtensions()
'audio/mpeg', if mimeType == 'audio/mpeg':
'audio/ogg' return True
) if not mimeType.startswith('audio/'):
if mimeType in audioMimeTypes: return False
ext = mimeType.split('/')[1]
if ext in extensions:
return True return True
return False return False