X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fcustom-validators%2Fvideos.ts;h=b33e088ebe25cdf4208f543e88c835de57d3bd16;hb=eb34ec30e0b57286fc6f85160490d2e973a3b0b1;hp=a9e859e54a000a3304533b0c2492fd4b529bb92b;hpb=7cde3b9c2e84ea20bb0aae4544598483cde9e22c;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts index a9e859e54..b33e088eb 100644 --- a/server/helpers/custom-validators/videos.ts +++ b/server/helpers/custom-validators/videos.ts @@ -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,