X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fcustom-validators%2Fvideos.ts;h=e99992236b5f2dca67c0872369d5a7ee3c6f1805;hb=de6310b2fcbb8a6b79c546b23dfa1920724faaa7;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..e99992236 100644 --- a/server/helpers/custom-validators/videos.ts +++ b/server/helpers/custom-validators/videos.ts @@ -8,7 +8,8 @@ import { VIDEO_LICENCES, VIDEO_PRIVACIES, VIDEO_RATE_TYPES, - VIDEO_STATES + VIDEO_STATES, + VIDEO_LIVE } from '../../initializers/constants' import { exists, isArray, isDateValid, isFileValid } from './misc' import * as magnetUtil from 'magnet-uri' @@ -20,15 +21,15 @@ function isVideoFilterValid (filter: VideoFilter) { } 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 +74,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) + return isFileValid(files, MIMETYPES.VIDEO.MIMETYPES_REGEX, 'videofile', null) } const videoImageTypes = CONSTRAINTS_FIELDS.VIDEOS.IMAGE.EXTNAME @@ -98,7 +95,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) {