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