aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-01-03 10:12:36 +0100
committerChocobozzz <me@florianbigard.com>2018-01-03 10:38:19 +0100
commit47564bbe2eeb2baae9b7e3f9b2b8d16522bc7e04 (patch)
tree25e2836baf3dfce6f422192d98332db1bfe65890 /server/helpers
parentc5911fd347c76e8bdc05ea9f3ee9efed4a58c236 (diff)
downloadPeerTube-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.ts5
-rw-r--r--server/helpers/custom-validators/activitypub/video-channels.ts30
-rw-r--r--server/helpers/custom-validators/activitypub/videos.ts6
-rw-r--r--server/helpers/custom-validators/misc.ts7
-rw-r--r--server/helpers/custom-validators/videos.ts5
-rw-r--r--server/helpers/utils.ts2
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'
5import { isActivityPubUrlValid } from './misc' 5import { isActivityPubUrlValid } from './misc'
6import { isDislikeActivityValid, isLikeActivityValid } from './rate' 6import { isDislikeActivityValid, isLikeActivityValid } from './rate'
7import { isUndoActivityValid } from './undo' 7import { isUndoActivityValid } from './undo'
8import { isVideoChannelDeleteActivityValid, isVideoChannelUpdateActivityValid } from './video-channels'
9import { isVideoCommentCreateActivityValid } from './video-comments' 8import { isVideoCommentCreateActivityValid } from './video-comments'
10import { 9import {
11 isVideoFlagValid, 10 isVideoFlagValid,
@@ -65,13 +64,11 @@ function checkCreateActivity (activity: any) {
65} 64}
66 65
67function checkUpdateActivity (activity: any) { 66function checkUpdateActivity (activity: any) {
68 return isVideoTorrentUpdateActivityValid(activity) || 67 return isVideoTorrentUpdateActivityValid(activity)
69 isVideoChannelUpdateActivityValid(activity)
70} 68}
71 69
72function checkDeleteActivity (activity: any) { 70function 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 @@
1import { isDateValid, isUUIDValid } from '../misc'
2import { isVideoChannelDescriptionValid, isVideoChannelNameValid } from '../video-channels'
3import { isActivityPubUrlValid, isBaseActivityValid } from './misc'
4
5function isVideoChannelUpdateActivityValid (activity: any) {
6 return isBaseActivityValid(activity, 'Update') &&
7 isVideoChannelObjectValid(activity.object)
8}
9
10function isVideoChannelDeleteActivityValid (activity: any) {
11 return isBaseActivityValid(activity, 'Delete')
12}
13
14function 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
26export {
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 @@
1import * as validator from 'validator' 1import * as validator from 'validator'
2import { ACTIVITY_PUB } from '../../../initializers' 2import { ACTIVITY_PUB } from '../../../initializers'
3import { exists, isDateValid, isUUIDValid } from '../misc' 3import { exists, isBooleanValid, isDateValid, isUUIDValid } from '../misc'
4import { 4import {
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
27function isBooleanValid (value: string) {
28 return typeof value === 'boolean' || (typeof value === 'string' && validator.isBoolean(value))
29}
30
27// --------------------------------------------------------------------------- 31// ---------------------------------------------------------------------------
28 32
29export { 33export {
@@ -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
33function isVideoNSFWValid (value: any) {
34 return typeof value === 'boolean' || (typeof value === 'string' && validator.isBoolean(value))
35}
36
37function isVideoDurationValid (value: string) { 33function 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'
3import { Model } from 'sequelize-typescript' 3import { Model } from 'sequelize-typescript'
4import { ResultList } from '../../shared' 4import { ResultList } from '../../shared'
5import { VideoResolution } from '../../shared/models/videos' 5import { VideoResolution } from '../../shared/models/videos'
6import { CONFIG, REMOTE_SCHEME, VIDEO_MIMETYPE_EXT } from '../initializers' 6import { CONFIG, REMOTE_SCHEME } from '../initializers'
7import { UserModel } from '../models/account/user' 7import { UserModel } from '../models/account/user'
8import { ActorModel } from '../models/activitypub/actor' 8import { ActorModel } from '../models/activitypub/actor'
9import { ApplicationModel } from '../models/application/application' 9import { ApplicationModel } from '../models/application/application'