X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fcustom-validators%2Fvideos.ts;h=07aadadb100f3596d0008d43def68431bd409f43;hb=40ff57078e15d5b86ee6b71e198b95d3feb78eaf;hp=d68de66092253e1f08bd88dacf28d0bc959d095f;hpb=608624252466acf9f1d9ee1c1170bd4fe4d18d18;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts index d68de6609..07aadadb1 100644 --- a/server/helpers/custom-validators/videos.ts +++ b/server/helpers/custom-validators/videos.ts @@ -1,25 +1,23 @@ -import { values } from 'lodash' -import * as validator from 'validator' import * as Promise from 'bluebird' import * as express from 'express' import 'express-validator' +import { values } from 'lodash' import 'multer' - +import * as validator from 'validator' +import { VideoRateType } from '../../../shared' +import { logger } from '../../helpers' import { CONSTRAINTS_FIELDS, + database as db, VIDEO_CATEGORIES, - VIDEO_LICENCES, VIDEO_LANGUAGES, - VIDEO_RATE_TYPES, + VIDEO_LICENCES, VIDEO_PRIVACIES, - database as db + VIDEO_RATE_TYPES } from '../../initializers' -import { isUserUsernameValid } from './users' -import { isArray, exists } from './misc' import { VideoInstance } from '../../models' -import { logger } from '../../helpers' -import { VideoRateType } from '../../../shared' import { isActivityPubUrlValid } from './activitypub/misc' +import { exists, isArray } from './misc' const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS const VIDEO_ABUSES_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_ABUSES @@ -69,6 +67,10 @@ function isVideoNSFWValid (value: any) { return typeof value === 'boolean' || (typeof value === 'string' && validator.isBoolean(value)) } +function isVideoDurationValid (value: string) { + return exists(value) && validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.DURATION) +} + function isVideoTruncatedDescriptionValid (value: string) { return exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.TRUNCATED_DESCRIPTION) } @@ -77,15 +79,6 @@ function isVideoDescriptionValid (value: string) { return exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.DESCRIPTION) } -function isVideoDurationValid (value: string) { - // https://www.w3.org/TR/activitystreams-vocabulary/#dfn-duration - return exists(value) && - typeof value === 'string' && - value.startsWith('PT') && - value.endsWith('S') && - validator.isInt(value.replace(/[^0-9]+/, ''), VIDEOS_CONSTRAINTS_FIELDS.DURATION) -} - function isVideoNameValid (value: string) { return exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.NAME) } @@ -112,10 +105,6 @@ function isVideoAbuseReasonValid (value: string) { return exists(value) && validator.isLength(value, VIDEO_ABUSES_CONSTRAINTS_FIELDS.REASON) } -function isVideoAbuseReporterUsernameValid (value: string) { - return isUserUsernameValid(value) -} - function isVideoViewsValid (value: string) { return exists(value) && validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.VIEWS) } @@ -201,7 +190,6 @@ export { isVideoNSFWValid, isVideoTruncatedDescriptionValid, isVideoDescriptionValid, - isVideoDurationValid, isVideoFileInfoHashValid, isVideoNameValid, isVideoTagsValid, @@ -209,7 +197,6 @@ export { isVideoThumbnailDataValid, isVideoFileExtnameValid, isVideoAbuseReasonValid, - isVideoAbuseReporterUsernameValid, isVideoFile, isVideoViewsValid, isVideoLikesValid, @@ -219,6 +206,7 @@ export { isVideoFileSizeValid, isVideoPrivacyValid, isRemoteVideoPrivacyValid, + isVideoDurationValid, isVideoFileResolutionValid, checkVideoExists, isVideoTagValid,