diff options
author | Chocobozzz <me@florianbigard.com> | 2018-01-03 10:12:36 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-01-03 10:38:19 +0100 |
commit | 47564bbe2eeb2baae9b7e3f9b2b8d16522bc7e04 (patch) | |
tree | 25e2836baf3dfce6f422192d98332db1bfe65890 /server/helpers | |
parent | c5911fd347c76e8bdc05ea9f3ee9efed4a58c236 (diff) | |
download | PeerTube-47564bbe2eeb2baae9b7e3f9b2b8d16522bc7e04.tar.gz PeerTube-47564bbe2eeb2baae9b7e3f9b2b8d16522bc7e04.tar.zst PeerTube-47564bbe2eeb2baae9b7e3f9b2b8d16522bc7e04.zip |
Add ability to disable video comments
Diffstat (limited to 'server/helpers')
-rw-r--r-- | server/helpers/custom-validators/activitypub/activity.ts | 5 | ||||
-rw-r--r-- | server/helpers/custom-validators/activitypub/video-channels.ts | 30 | ||||
-rw-r--r-- | server/helpers/custom-validators/activitypub/videos.ts | 6 | ||||
-rw-r--r-- | server/helpers/custom-validators/misc.ts | 7 | ||||
-rw-r--r-- | server/helpers/custom-validators/videos.ts | 5 | ||||
-rw-r--r-- | server/helpers/utils.ts | 2 |
6 files changed, 11 insertions, 44 deletions
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' | |||
5 | import { isActivityPubUrlValid } from './misc' | 5 | import { isActivityPubUrlValid } from './misc' |
6 | import { isDislikeActivityValid, isLikeActivityValid } from './rate' | 6 | import { isDislikeActivityValid, isLikeActivityValid } from './rate' |
7 | import { isUndoActivityValid } from './undo' | 7 | import { isUndoActivityValid } from './undo' |
8 | import { isVideoChannelDeleteActivityValid, isVideoChannelUpdateActivityValid } from './video-channels' | ||
9 | import { isVideoCommentCreateActivityValid } from './video-comments' | 8 | import { isVideoCommentCreateActivityValid } from './video-comments' |
10 | import { | 9 | import { |
11 | isVideoFlagValid, | 10 | isVideoFlagValid, |
@@ -65,13 +64,11 @@ function checkCreateActivity (activity: any) { | |||
65 | } | 64 | } |
66 | 65 | ||
67 | function checkUpdateActivity (activity: any) { | 66 | function checkUpdateActivity (activity: any) { |
68 | return isVideoTorrentUpdateActivityValid(activity) || | 67 | return isVideoTorrentUpdateActivityValid(activity) |
69 | isVideoChannelUpdateActivityValid(activity) | ||
70 | } | 68 | } |
71 | 69 | ||
72 | function checkDeleteActivity (activity: any) { | 70 | function checkDeleteActivity (activity: any) { |
73 | return isVideoTorrentDeleteActivityValid(activity) || | 71 | return isVideoTorrentDeleteActivityValid(activity) || |
74 | isVideoChannelDeleteActivityValid(activity) || | ||
75 | isActorDeleteActivityValid(activity) | 72 | isActorDeleteActivityValid(activity) |
76 | } | 73 | } |
77 | 74 | ||
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 @@ | |||
1 | import { isDateValid, isUUIDValid } from '../misc' | ||
2 | import { isVideoChannelDescriptionValid, isVideoChannelNameValid } from '../video-channels' | ||
3 | import { isActivityPubUrlValid, isBaseActivityValid } from './misc' | ||
4 | |||
5 | function isVideoChannelUpdateActivityValid (activity: any) { | ||
6 | return isBaseActivityValid(activity, 'Update') && | ||
7 | isVideoChannelObjectValid(activity.object) | ||
8 | } | ||
9 | |||
10 | function isVideoChannelDeleteActivityValid (activity: any) { | ||
11 | return isBaseActivityValid(activity, 'Delete') | ||
12 | } | ||
13 | |||
14 | function isVideoChannelObjectValid (videoChannel: any) { | ||
15 | return videoChannel.type === 'VideoChannel' && | ||
16 | isActivityPubUrlValid(videoChannel.id) && | ||
17 | isVideoChannelNameValid(videoChannel.name) && | ||
18 | isVideoChannelDescriptionValid(videoChannel.content) && | ||
19 | isDateValid(videoChannel.published) && | ||
20 | isDateValid(videoChannel.updated) && | ||
21 | isUUIDValid(videoChannel.uuid) | ||
22 | } | ||
23 | |||
24 | // --------------------------------------------------------------------------- | ||
25 | |||
26 | export { | ||
27 | isVideoChannelUpdateActivityValid, | ||
28 | isVideoChannelDeleteActivityValid, | ||
29 | isVideoChannelObjectValid | ||
30 | } | ||
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 @@ | |||
1 | import * as validator from 'validator' | 1 | import * as validator from 'validator' |
2 | import { ACTIVITY_PUB } from '../../../initializers' | 2 | import { ACTIVITY_PUB } from '../../../initializers' |
3 | import { exists, isDateValid, isUUIDValid } from '../misc' | 3 | import { exists, isBooleanValid, isDateValid, isUUIDValid } from '../misc' |
4 | import { | 4 | import { |
5 | isVideoAbuseReasonValid, | 5 | isVideoAbuseReasonValid, |
6 | isVideoDurationValid, | 6 | isVideoDurationValid, |
7 | isVideoNameValid, | 7 | isVideoNameValid, |
8 | isVideoNSFWValid, | ||
9 | isVideoTagValid, | 8 | isVideoTagValid, |
10 | isVideoTruncatedDescriptionValid, | 9 | isVideoTruncatedDescriptionValid, |
11 | isVideoViewsValid | 10 | isVideoViewsValid |
@@ -53,7 +52,8 @@ function isVideoTorrentObjectValid (video: any) { | |||
53 | (!video.licence || isRemoteIdentifierValid(video.licence)) && | 52 | (!video.licence || isRemoteIdentifierValid(video.licence)) && |
54 | (!video.language || isRemoteIdentifierValid(video.language)) && | 53 | (!video.language || isRemoteIdentifierValid(video.language)) && |
55 | isVideoViewsValid(video.views) && | 54 | isVideoViewsValid(video.views) && |
56 | isVideoNSFWValid(video.nsfw) && | 55 | isBooleanValid(video.nsfw) && |
56 | isBooleanValid(video.commentsEnabled) && | ||
57 | isDateValid(video.published) && | 57 | isDateValid(video.published) && |
58 | isDateValid(video.updated) && | 58 | isDateValid(video.updated) && |
59 | (!video.content || isRemoteVideoContentValid(video.mediaType, video.content)) && | 59 | (!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) { | |||
24 | return isIdValid(value) || isUUIDValid(value) | 24 | return isIdValid(value) || isUUIDValid(value) |
25 | } | 25 | } |
26 | 26 | ||
27 | function isBooleanValid (value: string) { | ||
28 | return typeof value === 'boolean' || (typeof value === 'string' && validator.isBoolean(value)) | ||
29 | } | ||
30 | |||
27 | // --------------------------------------------------------------------------- | 31 | // --------------------------------------------------------------------------- |
28 | 32 | ||
29 | export { | 33 | export { |
@@ -32,5 +36,6 @@ export { | |||
32 | isIdValid, | 36 | isIdValid, |
33 | isUUIDValid, | 37 | isUUIDValid, |
34 | isIdOrUUIDValid, | 38 | isIdOrUUIDValid, |
35 | isDateValid | 39 | isDateValid, |
40 | isBooleanValid | ||
36 | } | 41 | } |
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) { | |||
30 | return value === null || VIDEO_LANGUAGES[value] !== undefined | 30 | return value === null || VIDEO_LANGUAGES[value] !== undefined |
31 | } | 31 | } |
32 | 32 | ||
33 | function isVideoNSFWValid (value: any) { | ||
34 | return typeof value === 'boolean' || (typeof value === 'string' && validator.isBoolean(value)) | ||
35 | } | ||
36 | |||
37 | function isVideoDurationValid (value: string) { | 33 | function isVideoDurationValid (value: string) { |
38 | return exists(value) && validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.DURATION) | 34 | return exists(value) && validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.DURATION) |
39 | } | 35 | } |
@@ -131,7 +127,6 @@ export { | |||
131 | isVideoCategoryValid, | 127 | isVideoCategoryValid, |
132 | isVideoLicenceValid, | 128 | isVideoLicenceValid, |
133 | isVideoLanguageValid, | 129 | isVideoLanguageValid, |
134 | isVideoNSFWValid, | ||
135 | isVideoTruncatedDescriptionValid, | 130 | isVideoTruncatedDescriptionValid, |
136 | isVideoDescriptionValid, | 131 | isVideoDescriptionValid, |
137 | isVideoFileInfoHashValid, | 132 | isVideoFileInfoHashValid, |
diff --git a/server/helpers/utils.ts b/server/helpers/utils.ts index 7a32e286c..b61d6e3fa 100644 --- a/server/helpers/utils.ts +++ b/server/helpers/utils.ts | |||
@@ -3,7 +3,7 @@ import * as multer from 'multer' | |||
3 | import { Model } from 'sequelize-typescript' | 3 | import { Model } from 'sequelize-typescript' |
4 | import { ResultList } from '../../shared' | 4 | import { ResultList } from '../../shared' |
5 | import { VideoResolution } from '../../shared/models/videos' | 5 | import { VideoResolution } from '../../shared/models/videos' |
6 | import { CONFIG, REMOTE_SCHEME, VIDEO_MIMETYPE_EXT } from '../initializers' | 6 | import { CONFIG, REMOTE_SCHEME } from '../initializers' |
7 | import { UserModel } from '../models/account/user' | 7 | import { UserModel } from '../models/account/user' |
8 | import { ActorModel } from '../models/activitypub/actor' | 8 | import { ActorModel } from '../models/activitypub/actor' |
9 | import { ApplicationModel } from '../models/application/application' | 9 | import { ApplicationModel } from '../models/application/application' |