]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - 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
CommitLineData
74dc3bca 1import { CONSTRAINTS_FIELDS, MIMETYPES, VIDEO_LANGUAGES } from '../../initializers/constants'
40e87e9e 2import { exists, isFileValid } from './misc'
40e87e9e
C
3
4function isVideoCaptionLanguageValid (value: any) {
a1587156 5 return exists(value) && VIDEO_LANGUAGES[value] !== undefined
40e87e9e
C
6}
7
edaf5b86
C
8const videoCaptionTypesRegex = Object.keys(MIMETYPES.VIDEO_CAPTIONS.MIMETYPE_EXT)
9 .concat([ 'application/octet-stream' ]) // MacOS sends application/octet-stream
2769e297 10 .map(m => `(${m})`)
edaf5b86 11 .join('|')
40e87e9e 12function isVideoCaptionFile (files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[], field: string) {
f4001cf4 13 return isFileValid(files, videoCaptionTypesRegex, field, CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.FILE_SIZE.max)
40e87e9e
C
14}
15
40e87e9e
C
16// ---------------------------------------------------------------------------
17
18export {
19 isVideoCaptionFile,
3e753302 20 isVideoCaptionLanguageValid
40e87e9e 21}