From 8e10cf1a5a438a00e5f7e0691cb830769867cffc Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 15 Nov 2017 16:28:35 +0100 Subject: Fix video upload and videos list --- .../custom-validators/activitypub/videos.ts | 30 +++++++++++++--------- server/helpers/custom-validators/videos.ts | 15 ++++------- 2 files changed, 23 insertions(+), 22 deletions(-) (limited to 'server/helpers/custom-validators') diff --git a/server/helpers/custom-validators/activitypub/videos.ts b/server/helpers/custom-validators/activitypub/videos.ts index c9ecf1f3d..a46757397 100644 --- a/server/helpers/custom-validators/activitypub/videos.ts +++ b/server/helpers/custom-validators/activitypub/videos.ts @@ -1,20 +1,17 @@ import * as validator from 'validator' - -import { - ACTIVITY_PUB -} from '../../../initializers' -import { isDateValid, isUUIDValid } from '../misc' +import { ACTIVITY_PUB } from '../../../initializers' +import { exists, isDateValid, isUUIDValid } from '../misc' +import { isVideoChannelDescriptionValid, isVideoChannelNameValid } from '../video-channels' import { - isVideoViewsValid, - isVideoNSFWValid, - isVideoTruncatedDescriptionValid, isVideoDurationValid, isVideoNameValid, + isVideoNSFWValid, isVideoTagValid, - isVideoUrlValid + isVideoTruncatedDescriptionValid, + isVideoUrlValid, + isVideoViewsValid } from '../videos' -import { isVideoChannelDescriptionValid, isVideoChannelNameValid } from '../video-channels' -import { isActivityPubUrlValid, isBaseActivityValid } from './misc' +import { isBaseActivityValid } from './misc' function isVideoTorrentAddActivityValid (activity: any) { return isBaseActivityValid(activity, 'Add') && @@ -30,10 +27,19 @@ function isVideoTorrentDeleteActivityValid (activity: any) { return isBaseActivityValid(activity, 'Delete') } +function isActivityPubVideoDurationValid (value: string) { + // https://www.w3.org/TR/activitystreams-vocabulary/#dfn-duration + return exists(value) && + typeof value === 'string' && + value.startsWith('PT') && + value.endsWith('S') && + isVideoDurationValid(value.replace(/[^0-9]+/, '')) +} + function isVideoTorrentObjectValid (video: any) { return video.type === 'Video' && isVideoNameValid(video.name) && - isVideoDurationValid(video.duration) && + isActivityPubVideoDurationValid(video.duration) && isUUIDValid(video.uuid) && setValidRemoteTags(video) && isRemoteIdentifierValid(video.category) && diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts index 1505632da..c97c9a2ad 100644 --- a/server/helpers/custom-validators/videos.ts +++ b/server/helpers/custom-validators/videos.ts @@ -69,6 +69,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 +81,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) } @@ -197,7 +192,6 @@ export { isVideoNSFWValid, isVideoTruncatedDescriptionValid, isVideoDescriptionValid, - isVideoDurationValid, isVideoFileInfoHashValid, isVideoNameValid, isVideoTagsValid, @@ -214,6 +208,7 @@ export { isVideoFileSizeValid, isVideoPrivacyValid, isRemoteVideoPrivacyValid, + isVideoDurationValid, isVideoFileResolutionValid, checkVideoExists, isVideoTagValid, -- cgit v1.2.3