1 import { CONSTRAINTS_FIELDS, VIDEO_CAPTIONS_MIMETYPE_EXT, VIDEO_LANGUAGES, VIDEO_MIMETYPE_EXT } from '../../initializers'
2 import { exists, isFileValid } from './misc'
3 import { Response } from 'express'
4 import { VideoModel } from '../../models/video/video'
5 import { VideoCaptionModel } from '../../models/video/video-caption'
7 function isVideoCaptionLanguageValid (value: any) {
8 return exists(value) && VIDEO_LANGUAGES[ value ] !== undefined
11 const videoCaptionTypes = Object.keys(VIDEO_CAPTIONS_MIMETYPE_EXT).map(m => `(${m})`)
12 const videoCaptionTypesRegex = videoCaptionTypes.join('|')
13 function isVideoCaptionFile (files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[], field: string) {
14 return isFileValid(files, videoCaptionTypesRegex, field, CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.FILE_SIZE.max)
17 async function isVideoCaptionExist (video: VideoModel, language: string, res: Response) {
18 const videoCaption = await VideoCaptionModel.loadByVideoIdAndLanguage(video.id, language)
22 .json({ error: 'Video caption not found' })
28 res.locals.videoCaption = videoCaption
32 // ---------------------------------------------------------------------------
36 isVideoCaptionLanguageValid,