]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/helpers/custom-validators/video-captions.ts
emit more specific status codes on video upload (#3423)
[github/Chocobozzz/PeerTube.git] / server / helpers / custom-validators / video-captions.ts
1 import { CONSTRAINTS_FIELDS, MIMETYPES, VIDEO_LANGUAGES } from '../../initializers/constants'
2 import { exists, isFileValid } from './misc'
3
4 function isVideoCaptionLanguageValid (value: any) {
5 return exists(value) && VIDEO_LANGUAGES[value] !== undefined
6 }
7
8 const videoCaptionTypesRegex = Object.keys(MIMETYPES.VIDEO_CAPTIONS.MIMETYPE_EXT)
9 .concat([ 'application/octet-stream' ]) // MacOS sends application/octet-stream
10 .map(m => `(${m})`)
11 .join('|')
12 function isVideoCaptionFile (files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[], field: string) {
13 return isFileValid(files, videoCaptionTypesRegex, field, CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.FILE_SIZE.max)
14 }
15
16 // ---------------------------------------------------------------------------
17
18 export {
19 isVideoCaptionFile,
20 isVideoCaptionLanguageValid
21 }