]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/custom-validators/video-captions.ts
Add /accounts/:username/ratings endpoint (#1756)
[github/Chocobozzz/PeerTube.git] / server / helpers / custom-validators / video-captions.ts
index fd4dc740b31fd4fac0c400a3d38cf859eafb4365..8bd1390030bab4802697bf867da7f7260bc065c2 100644 (file)
@@ -1,4 +1,4 @@
-import { CONSTRAINTS_FIELDS, VIDEO_LANGUAGES } from '../../initializers'
+import { CONSTRAINTS_FIELDS, MIMETYPES, VIDEO_LANGUAGES } from '../../initializers'
 import { exists, isFileValid } from './misc'
 import { Response } from 'express'
 import { VideoModel } from '../../models/video/video'
@@ -8,16 +8,15 @@ function isVideoCaptionLanguageValid (value: any) {
   return exists(value) && VIDEO_LANGUAGES[ value ] !== undefined
 }
 
-const videoCaptionTypes = CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.EXTNAME
-                                          .map(v => v.replace('.', ''))
-                                          .join('|')
-const videoCaptionsTypesRegex = `text/(${videoCaptionTypes})`
-
+const videoCaptionTypes = Object.keys(MIMETYPES.VIDEO_CAPTIONS.MIMETYPE_EXT)
+                                .concat([ 'application/octet-stream' ]) // MacOS sends application/octet-stream ><
+                                .map(m => `(${m})`)
+const videoCaptionTypesRegex = videoCaptionTypes.join('|')
 function isVideoCaptionFile (files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[], field: string) {
-  return isFileValid(files, videoCaptionsTypesRegex, field, CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.FILE_SIZE.max)
+  return isFileValid(files, videoCaptionTypesRegex, field, CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.FILE_SIZE.max)
 }
 
-async function isVideoCaptionExist (video: VideoModel, language: string, res: Response) {
+async function doesVideoCaptionExist (video: VideoModel, language: string, res: Response) {
   const videoCaption = await VideoCaptionModel.loadByVideoIdAndLanguage(video.id, language)
 
   if (!videoCaption) {
@@ -37,5 +36,5 @@ async function isVideoCaptionExist (video: VideoModel, language: string, res: Re
 export {
   isVideoCaptionFile,
   isVideoCaptionLanguageValid,
-  isVideoCaptionExist
+  doesVideoCaptionExist
 }