1 import { CONSTRAINTS_FIELDS, VIDEO_LANGUAGES } 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 = CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.EXTNAME
12 .map(v => v.replace('.', ''))
14 const videoCaptionsTypesRegex = `text/(${videoCaptionTypes})`
16 function isVideoCaptionFile (files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[], field: string) {
17 return isFileValid(files, videoCaptionsTypesRegex, field, CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.FILE_SIZE.max)
20 async function isVideoCaptionExist (video: VideoModel, language: string, res: Response) {
21 const videoCaption = await VideoCaptionModel.loadByVideoIdAndLanguage(video.id, language)
25 .json({ error: 'Video caption not found' })
31 res.locals.videoCaption = videoCaption
35 // ---------------------------------------------------------------------------
39 isVideoCaptionLanguageValid,