X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fcustom-validators%2Fvideos.ts;h=b33e088ebe25cdf4208f543e88c835de57d3bd16;hb=37a44fc915eef2140e22ceb96aba6b6eb2509007;hp=e92ef9b92588e7c6054d6b1c089b6206d044b7e1;hpb=2b65c4e53511ccb85b17479cb1c62717afb8511c;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts index e92ef9b92..b33e088eb 100644 --- a/server/helpers/custom-validators/videos.ts +++ b/server/helpers/custom-validators/videos.ts @@ -1,34 +1,36 @@ +import { UploadFilesForCheck } from 'express' import { values } from 'lodash' -import * as validator from 'validator' +import * as magnetUtil from 'magnet-uri' +import validator from 'validator' import { VideoFilter, VideoPrivacy, VideoRateType } from '../../../shared' import { CONSTRAINTS_FIELDS, 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,11 +96,11 @@ 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) { - return value === VideoPrivacy.UNLISTED || value === VideoPrivacy.PUBLIC + return value === VideoPrivacy.UNLISTED || value === VideoPrivacy.PUBLIC || value === VideoPrivacy.INTERNAL } function isVideoOriginallyPublishedAtValid (value: string | null) { @@ -146,12 +144,12 @@ export { isVideoFPSResolutionValid, isScheduleVideoUpdatePrivacyValid, isVideoOriginallyPublishedAtValid, - isVideoFile, isVideoMagnetUriValid, isVideoStateValid, isVideoViewsValid, isVideoRatingTypeValid, isVideoFileExtnameValid, + isVideoFileMimeTypeValid, isVideoDurationValid, isVideoTagValid, isVideoPrivacyValid,