From 47564bbe2eeb2baae9b7e3f9b2b8d16522bc7e04 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 3 Jan 2018 10:12:36 +0100 Subject: Add ability to disable video comments --- .../custom-validators/activitypub/activity.ts | 5 +--- .../activitypub/video-channels.ts | 30 ---------------------- .../custom-validators/activitypub/videos.ts | 6 ++--- server/helpers/custom-validators/misc.ts | 7 ++++- server/helpers/custom-validators/videos.ts | 5 ---- 5 files changed, 10 insertions(+), 43 deletions(-) delete mode 100644 server/helpers/custom-validators/activitypub/video-channels.ts (limited to 'server/helpers/custom-validators') diff --git a/server/helpers/custom-validators/activitypub/activity.ts b/server/helpers/custom-validators/activitypub/activity.ts index f2e137061..fbdde10ad 100644 --- a/server/helpers/custom-validators/activitypub/activity.ts +++ b/server/helpers/custom-validators/activitypub/activity.ts @@ -5,7 +5,6 @@ import { isAnnounceActivityValid } from './announce' import { isActivityPubUrlValid } from './misc' import { isDislikeActivityValid, isLikeActivityValid } from './rate' import { isUndoActivityValid } from './undo' -import { isVideoChannelDeleteActivityValid, isVideoChannelUpdateActivityValid } from './video-channels' import { isVideoCommentCreateActivityValid } from './video-comments' import { isVideoFlagValid, @@ -65,13 +64,11 @@ function checkCreateActivity (activity: any) { } function checkUpdateActivity (activity: any) { - return isVideoTorrentUpdateActivityValid(activity) || - isVideoChannelUpdateActivityValid(activity) + return isVideoTorrentUpdateActivityValid(activity) } function checkDeleteActivity (activity: any) { return isVideoTorrentDeleteActivityValid(activity) || - isVideoChannelDeleteActivityValid(activity) || isActorDeleteActivityValid(activity) } diff --git a/server/helpers/custom-validators/activitypub/video-channels.ts b/server/helpers/custom-validators/activitypub/video-channels.ts deleted file mode 100644 index eb45c6372..000000000 --- a/server/helpers/custom-validators/activitypub/video-channels.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { isDateValid, isUUIDValid } from '../misc' -import { isVideoChannelDescriptionValid, isVideoChannelNameValid } from '../video-channels' -import { isActivityPubUrlValid, isBaseActivityValid } from './misc' - -function isVideoChannelUpdateActivityValid (activity: any) { - return isBaseActivityValid(activity, 'Update') && - isVideoChannelObjectValid(activity.object) -} - -function isVideoChannelDeleteActivityValid (activity: any) { - return isBaseActivityValid(activity, 'Delete') -} - -function isVideoChannelObjectValid (videoChannel: any) { - return videoChannel.type === 'VideoChannel' && - isActivityPubUrlValid(videoChannel.id) && - isVideoChannelNameValid(videoChannel.name) && - isVideoChannelDescriptionValid(videoChannel.content) && - isDateValid(videoChannel.published) && - isDateValid(videoChannel.updated) && - isUUIDValid(videoChannel.uuid) -} - -// --------------------------------------------------------------------------- - -export { - isVideoChannelUpdateActivityValid, - isVideoChannelDeleteActivityValid, - isVideoChannelObjectValid -} diff --git a/server/helpers/custom-validators/activitypub/videos.ts b/server/helpers/custom-validators/activitypub/videos.ts index ae1339611..37cd6965a 100644 --- a/server/helpers/custom-validators/activitypub/videos.ts +++ b/server/helpers/custom-validators/activitypub/videos.ts @@ -1,11 +1,10 @@ import * as validator from 'validator' import { ACTIVITY_PUB } from '../../../initializers' -import { exists, isDateValid, isUUIDValid } from '../misc' +import { exists, isBooleanValid, isDateValid, isUUIDValid } from '../misc' import { isVideoAbuseReasonValid, isVideoDurationValid, isVideoNameValid, - isVideoNSFWValid, isVideoTagValid, isVideoTruncatedDescriptionValid, isVideoViewsValid @@ -53,7 +52,8 @@ function isVideoTorrentObjectValid (video: any) { (!video.licence || isRemoteIdentifierValid(video.licence)) && (!video.language || isRemoteIdentifierValid(video.language)) && isVideoViewsValid(video.views) && - isVideoNSFWValid(video.nsfw) && + isBooleanValid(video.nsfw) && + isBooleanValid(video.commentsEnabled) && isDateValid(video.published) && isDateValid(video.updated) && (!video.content || isRemoteVideoContentValid(video.mediaType, video.content)) && diff --git a/server/helpers/custom-validators/misc.ts b/server/helpers/custom-validators/misc.ts index 160ec91f3..3903884ea 100644 --- a/server/helpers/custom-validators/misc.ts +++ b/server/helpers/custom-validators/misc.ts @@ -24,6 +24,10 @@ function isIdOrUUIDValid (value: string) { return isIdValid(value) || isUUIDValid(value) } +function isBooleanValid (value: string) { + return typeof value === 'boolean' || (typeof value === 'string' && validator.isBoolean(value)) +} + // --------------------------------------------------------------------------- export { @@ -32,5 +36,6 @@ export { isIdValid, isUUIDValid, isIdOrUUIDValid, - isDateValid + isDateValid, + isBooleanValid } diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts index ee9d0ed19..1a5fdb887 100644 --- a/server/helpers/custom-validators/videos.ts +++ b/server/helpers/custom-validators/videos.ts @@ -30,10 +30,6 @@ function isVideoLanguageValid (value: number) { return value === null || VIDEO_LANGUAGES[value] !== undefined } -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) } @@ -131,7 +127,6 @@ export { isVideoCategoryValid, isVideoLicenceValid, isVideoLanguageValid, - isVideoNSFWValid, isVideoTruncatedDescriptionValid, isVideoDescriptionValid, isVideoFileInfoHashValid, -- cgit v1.2.3