aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/custom-validators')
-rw-r--r--server/helpers/custom-validators/index.js2
-rw-r--r--server/helpers/custom-validators/remote/index.js11
-rw-r--r--server/helpers/custom-validators/remote/videos.js74
-rw-r--r--server/helpers/custom-validators/videos.js66
4 files changed, 100 insertions, 53 deletions
diff --git a/server/helpers/custom-validators/index.js b/server/helpers/custom-validators/index.js
index 96b5b20b9..9383e0304 100644
--- a/server/helpers/custom-validators/index.js
+++ b/server/helpers/custom-validators/index.js
@@ -2,12 +2,14 @@
2 2
3const miscValidators = require('./misc') 3const miscValidators = require('./misc')
4const podsValidators = require('./pods') 4const podsValidators = require('./pods')
5const remoteValidators = require('./remote')
5const usersValidators = require('./users') 6const usersValidators = require('./users')
6const videosValidators = require('./videos') 7const videosValidators = require('./videos')
7 8
8const validators = { 9const validators = {
9 misc: miscValidators, 10 misc: miscValidators,
10 pods: podsValidators, 11 pods: podsValidators,
12 remote: remoteValidators,
11 users: usersValidators, 13 users: usersValidators,
12 videos: videosValidators 14 videos: videosValidators
13} 15}
diff --git a/server/helpers/custom-validators/remote/index.js b/server/helpers/custom-validators/remote/index.js
new file mode 100644
index 000000000..1939a95f4
--- /dev/null
+++ b/server/helpers/custom-validators/remote/index.js
@@ -0,0 +1,11 @@
1'use strict'
2
3const remoteVideosValidators = require('./videos')
4
5const validators = {
6 videos: remoteVideosValidators
7}
8
9// ---------------------------------------------------------------------------
10
11module.exports = validators
diff --git a/server/helpers/custom-validators/remote/videos.js b/server/helpers/custom-validators/remote/videos.js
new file mode 100644
index 000000000..c3ca00e1c
--- /dev/null
+++ b/server/helpers/custom-validators/remote/videos.js
@@ -0,0 +1,74 @@
1'use strict'
2
3const videosValidators = require('../videos')
4const miscValidators = require('../misc')
5
6const remoteVideosValidators = {
7 isEachRemoteRequestVideosValid
8}
9
10function isEachRemoteRequestVideosValid (requests) {
11 return miscValidators.isArray(requests) &&
12 requests.every(function (request) {
13 const video = request.data
14 return (
15 isRequestTypeAddValid(request.type) &&
16 videosValidators.isVideoAuthorValid(video.author) &&
17 videosValidators.isVideoDateValid(video.createdAt) &&
18 videosValidators.isVideoDateValid(video.updatedAt) &&
19 videosValidators.isVideoDescriptionValid(video.description) &&
20 videosValidators.isVideoDurationValid(video.duration) &&
21 videosValidators.isVideoInfoHashValid(video.infoHash) &&
22 videosValidators.isVideoNameValid(video.name) &&
23 videosValidators.isVideoTagsValid(video.tags) &&
24 videosValidators.isVideoThumbnailDataValid(video.thumbnailData) &&
25 videosValidators.isVideoRemoteIdValid(video.remoteId) &&
26 videosValidators.isVideoExtnameValid(video.extname)
27 ) ||
28 (
29 isRequestTypeUpdateValid(request.type) &&
30 videosValidators.isVideoDateValid(video.createdAt) &&
31 videosValidators.isVideoDateValid(video.updatedAt) &&
32 videosValidators.isVideoDescriptionValid(video.description) &&
33 videosValidators.isVideoDurationValid(video.duration) &&
34 videosValidators.isVideoInfoHashValid(video.infoHash) &&
35 videosValidators.isVideoNameValid(video.name) &&
36 videosValidators.isVideoTagsValid(video.tags) &&
37 videosValidators.isVideoRemoteIdValid(video.remoteId) &&
38 videosValidators.isVideoExtnameValid(video.extname)
39 ) ||
40 (
41 isRequestTypeRemoveValid(request.type) &&
42 videosValidators.isVideoNameValid(video.name) &&
43 videosValidators.isVideoRemoteIdValid(video.remoteId)
44 ) ||
45 (
46 isRequestTypeReportAbuseValid(request.type) &&
47 videosValidators.isVideoRemoteIdValid(request.data.videoRemoteId) &&
48 videosValidators.isVideoAbuseReasonValid(request.data.reportReason) &&
49 videosValidators.isVideoAbuseReporterUsernameValid(request.data.reporterUsername)
50 )
51 })
52}
53
54// ---------------------------------------------------------------------------
55
56module.exports = remoteVideosValidators
57
58// ---------------------------------------------------------------------------
59
60function isRequestTypeAddValid (value) {
61 return value === 'add'
62}
63
64function isRequestTypeUpdateValid (value) {
65 return value === 'update'
66}
67
68function isRequestTypeRemoveValid (value) {
69 return value === 'remove'
70}
71
72function isRequestTypeReportAbuseValid (value) {
73 return value === 'report-abuse'
74}
diff --git a/server/helpers/custom-validators/videos.js b/server/helpers/custom-validators/videos.js
index 8448386d9..7f727854d 100644
--- a/server/helpers/custom-validators/videos.js
+++ b/server/helpers/custom-validators/videos.js
@@ -6,9 +6,9 @@ const constants = require('../../initializers/constants')
6const usersValidators = require('./users') 6const usersValidators = require('./users')
7const miscValidators = require('./misc') 7const miscValidators = require('./misc')
8const VIDEOS_CONSTRAINTS_FIELDS = constants.CONSTRAINTS_FIELDS.VIDEOS 8const VIDEOS_CONSTRAINTS_FIELDS = constants.CONSTRAINTS_FIELDS.VIDEOS
9const VIDEO_ABUSES_CONSTRAINTS_FIELDS = constants.CONSTRAINTS_FIELDS.VIDEO_ABUSES
9 10
10const videosValidators = { 11const videosValidators = {
11 isEachRemoteVideosValid,
12 isVideoAuthorValid, 12 isVideoAuthorValid,
13 isVideoDateValid, 13 isVideoDateValid,
14 isVideoDescriptionValid, 14 isVideoDescriptionValid,
@@ -17,45 +17,11 @@ const videosValidators = {
17 isVideoNameValid, 17 isVideoNameValid,
18 isVideoTagsValid, 18 isVideoTagsValid,
19 isVideoThumbnailValid, 19 isVideoThumbnailValid,
20 isVideoThumbnailDataValid 20 isVideoThumbnailDataValid,
21} 21 isVideoExtnameValid,
22 22 isVideoRemoteIdValid,
23function isEachRemoteVideosValid (requests) { 23 isVideoAbuseReasonValid,
24 return miscValidators.isArray(requests) && 24 isVideoAbuseReporterUsernameValid
25 requests.every(function (request) {
26 const video = request.data
27 return (
28 isRequestTypeAddValid(request.type) &&
29 isVideoAuthorValid(video.author) &&
30 isVideoDateValid(video.createdAt) &&
31 isVideoDateValid(video.updatedAt) &&
32 isVideoDescriptionValid(video.description) &&
33 isVideoDurationValid(video.duration) &&
34 isVideoInfoHashValid(video.infoHash) &&
35 isVideoNameValid(video.name) &&
36 isVideoTagsValid(video.tags) &&
37 isVideoThumbnailDataValid(video.thumbnailData) &&
38 isVideoRemoteIdValid(video.remoteId) &&
39 isVideoExtnameValid(video.extname)
40 ) ||
41 (
42 isRequestTypeUpdateValid(request.type) &&
43 isVideoDateValid(video.createdAt) &&
44 isVideoDateValid(video.updatedAt) &&
45 isVideoDescriptionValid(video.description) &&
46 isVideoDurationValid(video.duration) &&
47 isVideoInfoHashValid(video.infoHash) &&
48 isVideoNameValid(video.name) &&
49 isVideoTagsValid(video.tags) &&
50 isVideoRemoteIdValid(video.remoteId) &&
51 isVideoExtnameValid(video.extname)
52 ) ||
53 (
54 isRequestTypeRemoveValid(request.type) &&
55 isVideoNameValid(video.name) &&
56 isVideoRemoteIdValid(video.remoteId)
57 )
58 })
59} 25}
60 26
61function isVideoAuthorValid (value) { 27function isVideoAuthorValid (value) {
@@ -107,20 +73,14 @@ function isVideoRemoteIdValid (value) {
107 return validator.isUUID(value, 4) 73 return validator.isUUID(value, 4)
108} 74}
109 75
110// --------------------------------------------------------------------------- 76function isVideoAbuseReasonValid (value) {
111 77 return validator.isLength(value, VIDEO_ABUSES_CONSTRAINTS_FIELDS.REASON)
112module.exports = videosValidators
113
114// ---------------------------------------------------------------------------
115
116function isRequestTypeAddValid (value) {
117 return value === 'add'
118} 78}
119 79
120function isRequestTypeUpdateValid (value) { 80function isVideoAbuseReporterUsernameValid (value) {
121 return value === 'update' 81 return usersValidators.isUserUsernameValid(value)
122} 82}
123 83
124function isRequestTypeRemoveValid (value) { 84// ---------------------------------------------------------------------------
125 return value === 'remove' 85
126} 86module.exports = videosValidators