X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Finitializers%2Fconstants.ts;h=171e9e9c2496294e07d28939ec95e74f18270250;hb=2cfd3b7eb945063242459bfb26cd654cd5938891;hp=ca6c2a7ffbb2ea6dc68d0d172ab7e760c47f3b74;hpb=d573926e9b94fb19c8f51c53f71fc853182e1761;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index ca6c2a7ff..171e9e9c2 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts @@ -23,7 +23,7 @@ import { CONFIG, registerConfigChangedHandler } from './config' // --------------------------------------------------------------------------- -const LAST_MIGRATION_VERSION = 525 +const LAST_MIGRATION_VERSION = 530 // --------------------------------------------------------------------------- @@ -417,12 +417,15 @@ const MIMETYPES = { 'audio/x-ms-wma': '.wma', 'audio/wav': '.wav', 'audio/x-flac': '.flac', - 'audio/flac': '.flac' + 'audio/flac': '.flac', + '‎audio/aac': '.aac', + 'audio/ac3': '.ac3' }, EXT_MIMETYPE: null as { [ id: string ]: string } }, VIDEO: { - MIMETYPE_EXT: null as { [ id: string ]: string }, + MIMETYPE_EXT: null as { [ id: string ]: string | string[] }, + MIMETYPES_REGEX: null as string, EXT_MIMETYPE: null as { [ id: string ]: string } }, IMAGE: { @@ -542,8 +545,8 @@ const STATIC_DOWNLOAD_PATHS = { } const LAZY_STATIC_PATHS = { AVATARS: '/lazy-static/avatars/', - PREVIEWS: '/static/previews/', - VIDEO_CAPTIONS: '/static/video-captions/' + PREVIEWS: '/lazy-static/previews/', + VIDEO_CAPTIONS: '/lazy-static/video-captions/' } // Cache control @@ -823,23 +826,58 @@ export { function buildVideoMimetypeExt () { const data = { + // streamable formats that warrant cross-browser compatibility 'video/webm': '.webm', - 'video/ogg': '.ogv', + // We'll add .ogg if additional extensions are enabled + // We could add .ogg here but since it could be an audio file, + // it would be confusing for users because PeerTube will refuse their file (based on the mimetype) + 'video/ogg': [ '.ogv' ], 'video/mp4': '.mp4' } if (CONFIG.TRANSCODING.ENABLED) { if (CONFIG.TRANSCODING.ALLOW_ADDITIONAL_EXTENSIONS) { + data['video/ogg'].push('.ogg') + Object.assign(data, { - 'video/quicktime': '.mov', - 'video/x-msvideo': '.avi', - 'video/x-flv': '.flv', 'video/x-matroska': '.mkv', - 'video/avi': '.avi', + + // Developed by Apple + 'video/quicktime': [ '.mov', '.qt', '.mqv' ], // often used as output format by editing software 'video/x-m4v': '.m4v', + 'video/m4v': '.m4v', + + // Developed by the Adobe Flash Platform + 'video/x-flv': '.flv', + 'video/x-f4v': '.f4v', // replacement for flv + + // Developed by Microsoft + 'video/x-ms-wmv': '.wmv', + 'video/x-msvideo': '.avi', + 'video/avi': '.avi', + + // Developed by 3GPP + // common video formats for cell phones + 'video/3gpp': [ '.3gp', '.3gpp' ], + 'video/3gpp2': [ '.3g2', '.3gpp2' ], + + // Developed by FFmpeg/Mplayer + 'application/x-nut': '.nut', + + // The standard video format used by many Sony and Panasonic HD camcorders. + // It is also used for storing high definition video on Blu-ray discs. + 'video/mp2t': '.mts', + 'video/m2ts': '.m2ts', + + // Old formats reliant on MPEG-1/MPEG-2 + 'video/mpv': '.mpv', + 'video/mpeg2': '.m2v', + 'video/mpeg': [ '.m1v', '.mpg', '.mpe', '.mpeg', '.vob' ], + 'video/dvd': '.vob', + // Could be anything 'application/octet-stream': null, - 'video/m4v': '.m4v' + 'application/mxf': '.mxf' // often used as exchange format by editing software }) } @@ -862,14 +900,36 @@ function updateWebserverUrls () { function updateWebserverConfig () { MIMETYPES.VIDEO.MIMETYPE_EXT = buildVideoMimetypeExt() - MIMETYPES.VIDEO.EXT_MIMETYPE = invert(MIMETYPES.VIDEO.MIMETYPE_EXT) + MIMETYPES.VIDEO.MIMETYPES_REGEX = buildMimetypesRegex(MIMETYPES.VIDEO.MIMETYPE_EXT) + ACTIVITY_PUB.URL_MIME_TYPES.VIDEO = Object.keys(MIMETYPES.VIDEO.MIMETYPE_EXT) - CONSTRAINTS_FIELDS.VIDEOS.EXTNAME = buildVideosExtname() + MIMETYPES.VIDEO.EXT_MIMETYPE = buildVideoExtMimetype(MIMETYPES.VIDEO.MIMETYPE_EXT) + + CONSTRAINTS_FIELDS.VIDEOS.EXTNAME = Object.keys(MIMETYPES.VIDEO.EXT_MIMETYPE) +} + +function buildVideoExtMimetype (obj: { [ id: string ]: string | string[] }) { + const result: { [id: string]: string } = {} + + for (const mimetype of Object.keys(obj)) { + const value = obj[mimetype] + if (!value) continue + + const extensions = Array.isArray(value) ? value : [ value ] + + for (const extension of extensions) { + result[extension] = mimetype + } + } + + return result } -function buildVideosExtname () { - return Object.keys(MIMETYPES.VIDEO.EXT_MIMETYPE) +function buildMimetypesRegex (obj: { [id: string]: string | string[] }) { + return Object.keys(obj) + .map(m => `(${m})`) + .join('|') } function loadLanguages () { @@ -896,7 +956,9 @@ function buildLanguages () { jsl: true, // Japanese sign language sfs: true, // South African sign language swl: true, // Swedish sign language - rsl: true, // Russian sign language: true + rsl: true, // Russian sign language + + kab: true, // Kabyle epo: true, // Esperanto tlh: true, // Klingon