PeerTube/server/helpers/custom-validators/video-captions.ts

22 lines
955 B
TypeScript
Raw Normal View History

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