aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators/videos.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/custom-validators/videos.js')
-rw-r--r--server/helpers/custom-validators/videos.js66
1 files changed, 13 insertions, 53 deletions
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