]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/custom-validators/videos.ts
Merge branch 'release/3.2.0' into develop
[github/Chocobozzz/PeerTube.git] / server / helpers / custom-validators / videos.ts
index a9e859e54a000a3304533b0c2492fd4b529bb92b..b33e088ebe25cdf4208f543e88c835de57d3bd16 100644 (file)
@@ -1,4 +1,6 @@
+import { UploadFilesForCheck } from 'express'
 import { values } from 'lodash'
+import * as magnetUtil from 'magnet-uri'
 import validator from 'validator'
 import { VideoFilter, VideoPrivacy, VideoRateType } from '../../../shared'
 import {
@@ -6,29 +8,29 @@ import {
   MIMETYPES,
   VIDEO_CATEGORIES,
   VIDEO_LICENCES,
+  VIDEO_LIVE,
   VIDEO_PRIVACIES,
   VIDEO_RATE_TYPES,
   VIDEO_STATES
 } from '../../initializers/constants'
-import { exists, isArray, isDateValid, isFileValid } from './misc'
-import * as magnetUtil from 'magnet-uri'
+import { exists, isArray, isDateValid, isFileMimeTypeValid, isFileValid } from './misc'
 
 const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS
 
 function isVideoFilterValid (filter: VideoFilter) {
-  return filter === 'local' || filter === 'all-local'
+  return filter === 'local' || filter === 'all-local' || filter === 'all'
 }
 
 function isVideoCategoryValid (value: any) {
-  return value === null || VIDEO_CATEGORIES[ value ] !== undefined
+  return value === null || VIDEO_CATEGORIES[value] !== undefined
 }
 
 function isVideoStateValid (value: any) {
-  return exists(value) && VIDEO_STATES[ value ] !== undefined
+  return exists(value) && VIDEO_STATES[value] !== undefined
 }
 
 function isVideoLicenceValid (value: any) {
-  return value === null || VIDEO_LICENCES[ value ] !== undefined
+  return value === null || VIDEO_LICENCES[value] !== undefined
 }
 
 function isVideoLanguageValid (value: any) {
@@ -73,19 +75,15 @@ function isVideoViewsValid (value: string) {
 }
 
 function isVideoRatingTypeValid (value: string) {
-  return value === 'none' || values(VIDEO_RATE_TYPES).indexOf(value as VideoRateType) !== -1
+  return value === 'none' || values(VIDEO_RATE_TYPES).includes(value as VideoRateType)
 }
 
 function isVideoFileExtnameValid (value: string) {
-  return exists(value) && MIMETYPES.VIDEO.EXT_MIMETYPE[value] !== undefined
+  return exists(value) && (value === VIDEO_LIVE.EXTENSION || MIMETYPES.VIDEO.EXT_MIMETYPE[value] !== undefined)
 }
 
-function isVideoFile (files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[]) {
-  const videoFileTypesRegex = Object.keys(MIMETYPES.VIDEO.MIMETYPE_EXT)
-                                    .map(m => `(${m})`)
-                                    .join('|')
-
-  return isFileValid(files, videoFileTypesRegex, 'videofile', null)
+function isVideoFileMimeTypeValid (files: UploadFilesForCheck) {
+  return isFileMimeTypeValid(files, MIMETYPES.VIDEO.MIMETYPES_REGEX, 'videofile')
 }
 
 const videoImageTypes = CONSTRAINTS_FIELDS.VIDEOS.IMAGE.EXTNAME
@@ -98,7 +96,7 @@ function isVideoImage (files: { [ fieldname: string ]: Express.Multer.File[] } |
 }
 
 function isVideoPrivacyValid (value: number) {
-  return VIDEO_PRIVACIES[ value ] !== undefined
+  return VIDEO_PRIVACIES[value] !== undefined
 }
 
 function isScheduleVideoUpdatePrivacyValid (value: number) {
@@ -146,12 +144,12 @@ export {
   isVideoFPSResolutionValid,
   isScheduleVideoUpdatePrivacyValid,
   isVideoOriginallyPublishedAtValid,
-  isVideoFile,
   isVideoMagnetUriValid,
   isVideoStateValid,
   isVideoViewsValid,
   isVideoRatingTypeValid,
   isVideoFileExtnameValid,
+  isVideoFileMimeTypeValid,
   isVideoDurationValid,
   isVideoTagValid,
   isVideoPrivacyValid,