2019-04-11 12:26:41 +00:00
|
|
|
import { CONSTRAINTS_FIELDS, MIMETYPES, VIDEO_LANGUAGES } from '../../initializers/constants'
|
2018-07-12 17:02:00 +00:00
|
|
|
import { exists, isFileValid } from './misc'
|
|
|
|
|
|
|
|
function isVideoCaptionLanguageValid (value: any) {
|
2020-01-31 15:56:52 +00:00
|
|
|
return exists(value) && VIDEO_LANGUAGES[value] !== undefined
|
2018-07-12 17:02:00 +00:00
|
|
|
}
|
|
|
|
|
2018-12-11 13:52:50 +00:00
|
|
|
const videoCaptionTypes = Object.keys(MIMETYPES.VIDEO_CAPTIONS.MIMETYPE_EXT)
|
2018-08-06 09:45:24 +00:00
|
|
|
.concat([ 'application/octet-stream' ]) // MacOS sends application/octet-stream ><
|
|
|
|
.map(m => `(${m})`)
|
2018-07-16 12:22:16 +00:00
|
|
|
const videoCaptionTypesRegex = videoCaptionTypes.join('|')
|
2018-07-12 17:02:00 +00:00
|
|
|
function isVideoCaptionFile (files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[], field: string) {
|
2018-07-16 12:22:16 +00:00
|
|
|
return isFileValid(files, videoCaptionTypesRegex, field, CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.FILE_SIZE.max)
|
2018-07-12 17:02:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
isVideoCaptionFile,
|
2019-07-23 08:40:39 +00:00
|
|
|
isVideoCaptionLanguageValid
|
2018-07-12 17:02:00 +00:00
|
|
|
}
|