aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers/constants.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/initializers/constants.ts')
-rw-r--r--server/initializers/constants.ts41
1 files changed, 34 insertions, 7 deletions
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts
index 573d86b60..ebbdba262 100644
--- a/server/initializers/constants.ts
+++ b/server/initializers/constants.ts
@@ -422,7 +422,8 @@ const MIMETYPES = {
422 EXT_MIMETYPE: null as { [ id: string ]: string } 422 EXT_MIMETYPE: null as { [ id: string ]: string }
423 }, 423 },
424 VIDEO: { 424 VIDEO: {
425 MIMETYPE_EXT: null as { [ id: string ]: string }, 425 MIMETYPE_EXT: null as { [ id: string ]: string | string[] },
426 MIMETYPES_REGEX: null as string,
426 EXT_MIMETYPE: null as { [ id: string ]: string } 427 EXT_MIMETYPE: null as { [ id: string ]: string }
427 }, 428 },
428 IMAGE: { 429 IMAGE: {
@@ -825,15 +826,19 @@ function buildVideoMimetypeExt () {
825 const data = { 826 const data = {
826 // streamable formats that warrant cross-browser compatibility 827 // streamable formats that warrant cross-browser compatibility
827 'video/webm': '.webm', 828 'video/webm': '.webm',
828 'video/ogg': '.ogv', 829 // We'll add .ogg if additional extensions are enabled
830 // We could add .ogg here but since it could be an audio file,
831 // it would be confusing for users because PeerTube will refuse their file (based on the mimetype)
832 'video/ogg': [ '.ogv' ],
829 'video/mp4': '.mp4' 833 'video/mp4': '.mp4'
830 } 834 }
831 835
832 if (CONFIG.TRANSCODING.ENABLED) { 836 if (CONFIG.TRANSCODING.ENABLED) {
833 if (CONFIG.TRANSCODING.ALLOW_ADDITIONAL_EXTENSIONS) { 837 if (CONFIG.TRANSCODING.ALLOW_ADDITIONAL_EXTENSIONS) {
838 data['video/ogg'].push('.ogg')
839
834 Object.assign(data, { 840 Object.assign(data, {
835 'video/x-matroska': '.mkv', 841 'video/x-matroska': '.mkv',
836 'video/ogg': '.ogg',
837 842
838 // Developed by Apple 843 // Developed by Apple
839 'video/quicktime': '.mov', // often used as output format by editing software 844 'video/quicktime': '.mov', // often used as output format by editing software
@@ -892,14 +897,36 @@ function updateWebserverUrls () {
892 897
893function updateWebserverConfig () { 898function updateWebserverConfig () {
894 MIMETYPES.VIDEO.MIMETYPE_EXT = buildVideoMimetypeExt() 899 MIMETYPES.VIDEO.MIMETYPE_EXT = buildVideoMimetypeExt()
895 MIMETYPES.VIDEO.EXT_MIMETYPE = invert(MIMETYPES.VIDEO.MIMETYPE_EXT) 900 MIMETYPES.VIDEO.MIMETYPES_REGEX = buildMimetypesRegex(MIMETYPES.VIDEO.MIMETYPE_EXT)
901
896 ACTIVITY_PUB.URL_MIME_TYPES.VIDEO = Object.keys(MIMETYPES.VIDEO.MIMETYPE_EXT) 902 ACTIVITY_PUB.URL_MIME_TYPES.VIDEO = Object.keys(MIMETYPES.VIDEO.MIMETYPE_EXT)
897 903
898 CONSTRAINTS_FIELDS.VIDEOS.EXTNAME = buildVideosExtname() 904 MIMETYPES.VIDEO.EXT_MIMETYPE = buildVideoExtMimetype(MIMETYPES.VIDEO.MIMETYPE_EXT)
905
906 CONSTRAINTS_FIELDS.VIDEOS.EXTNAME = Object.keys(MIMETYPES.VIDEO.EXT_MIMETYPE)
907}
908
909function buildVideoExtMimetype (obj: { [ id: string ]: string | string[] }) {
910 const result: { [id: string]: string } = {}
911
912 for (const mimetype of Object.keys(obj)) {
913 const value = obj[mimetype]
914 if (!value) continue
915
916 const extensions = Array.isArray(value) ? value : [ value ]
917
918 for (const extension of extensions) {
919 result[extension] = mimetype
920 }
921 }
922
923 return result
899} 924}
900 925
901function buildVideosExtname () { 926function buildMimetypesRegex (obj: { [id: string]: string | string[] }) {
902 return Object.keys(MIMETYPES.VIDEO.EXT_MIMETYPE).filter(e => e !== 'null') 927 return Object.keys(obj)
928 .map(m => `(${m})`)
929 .join('|')
903} 930}
904 931
905function loadLanguages () { 932function loadLanguages () {