Tidying of mime types

This commit is contained in:
bashrc committed 2021-08-03 10:09:04 +01:00
1 parent b30d256faa
commit beb451baf7
3 files changed
+36 -33

No files matched your search

+1
View File
@@ -951,6 +951,7 @@ def saveMediaInFormPOST(mediaBytes, debug: bool,
'ogv': 'video/ogv',
'mp3': 'audio/mpeg',
'ogg': 'audio/ogg',
'flac': 'audio/flac',
'zip': 'application/zip'
}
detectedExtension = None
+13 -12
View File
@@ -297,6 +297,18 @@ def isArtist(baseDir: str, nickname: str) -> bool:
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() -> []:
"""Returns a list of the possible image file extensions
"""
@@ -337,18 +349,6 @@ def getImageExtensionFromMimeType(contentType: str) -> str:
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() -> []:
"""Returns a list of the possible media file extensions
"""
@@ -2216,6 +2216,7 @@ def mediaFileMimeType(filename: str) -> str:
'avif': 'image/avif',
'mp3': 'audio/mpeg',
'ogg': 'audio/ogg',
'flac': 'audio/flac',
'mp4': 'video/mp4',
'ogv': 'video/ogv'
}
+22 -21
View File
@@ -12,7 +12,6 @@ from collections import OrderedDict
from session import getJson
from utils import isAccountDir
from utils import removeHtml
from utils import getImageExtensions
from utils import getProtocolPrefixes
from utils import loadJson
from utils import getCachedPostFilename
@@ -20,6 +19,9 @@ from utils import getConfigParam
from utils import acctDir
from utils import getNicknameFromActor
from utils import isfloat
from utils import getAudioExtensions
from utils import getVideoExtensions
from utils import getImageExtensions
from cache import storePersonInCache
from content import addHtmlTags
from content import replaceEmojiFromTags
@@ -793,15 +795,13 @@ def addEmojiToDisplayName(baseDir: str, httpPrefix: str,
def _isImageMimeType(mimeType: str) -> bool:
"""Is the given mime type an image?
"""
imageMimeTypes = (
'image/png',
'image/jpeg',
'image/webp',
'image/avif',
'image/svg+xml',
'image/gif'
)
if mimeType in imageMimeTypes:
extensions = getImageExtensions()
if mimeType == 'image/svg+xml':
return True
if not mimeType.startswith('image/'):
return False
ext = mimeType.split('/')[1]
if ext in extensions:
return True
return False
@@ -809,12 +809,11 @@ def _isImageMimeType(mimeType: str) -> bool:
def _isVideoMimeType(mimeType: str) -> bool:
"""Is the given mime type a video?
"""
videoMimeTypes = (
'video/mp4',
'video/webm',
'video/ogv'
)
if mimeType in videoMimeTypes:
extensions = getVideoExtensions()
if not mimeType.startswith('video/'):
return False
ext = mimeType.split('/')[1]
if ext in extensions:
return True
return False
@@ -822,11 +821,13 @@ def _isVideoMimeType(mimeType: str) -> bool:
def _isAudioMimeType(mimeType: str) -> bool:
"""Is the given mime type an audio file?
"""
audioMimeTypes = (
'audio/mpeg',
'audio/ogg'
)
if mimeType in audioMimeTypes:
extensions = getAudioExtensions()
if mimeType == 'audio/mpeg':
return True
if not mimeType.startswith('audio/'):
return False
ext = mimeType.split('/')[1]
if ext in extensions:
return True
return False