aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/customValidators.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/customValidators.js')
-rw-r--r--server/helpers/customValidators.js48
1 files changed, 29 insertions, 19 deletions
diff --git a/server/helpers/customValidators.js b/server/helpers/customValidators.js
index 9c3ff38ef..a6cf680e5 100644
--- a/server/helpers/customValidators.js
+++ b/server/helpers/customValidators.js
@@ -7,8 +7,7 @@ const VIDEOS_CONSTRAINTS_FIELDS = constants.VIDEOS_CONSTRAINTS_FIELDS
7 7
8const customValidators = { 8const customValidators = {
9 exists: exists, 9 exists: exists,
10 isEachAddRemoteVideosValid: isEachAddRemoteVideosValid, 10 isEachRemoteVideosValid: isEachRemoteVideosValid,
11 isEachRemoveRemoteVideosValid: isEachRemoveRemoteVideosValid,
12 isArray: isArray, 11 isArray: isArray,
13 isVideoAuthorValid: isVideoAuthorValid, 12 isVideoAuthorValid: isVideoAuthorValid,
14 isVideoDateValid: isVideoDateValid, 13 isVideoDateValid: isVideoDateValid,
@@ -25,23 +24,26 @@ function exists (value) {
25 return value !== undefined && value !== null 24 return value !== undefined && value !== null
26} 25}
27 26
28function isEachAddRemoteVideosValid (videos) { 27function isEachRemoteVideosValid (requests) {
29 return videos.every(function (video) { 28 return requests.every(function (request) {
30 return isVideoAuthorValid(video.author) && 29 const video = request.data
31 isVideoDateValid(video.createdDate) && 30 return (
32 isVideoDescriptionValid(video.description) && 31 isRequestTypeAddValid(request.type) &&
33 isVideoDurationValid(video.duration) && 32 isVideoAuthorValid(video.author) &&
34 isVideoMagnetUriValid(video.magnetUri) && 33 isVideoDateValid(video.createdDate) &&
35 isVideoNameValid(video.name) && 34 isVideoDescriptionValid(video.description) &&
36 isVideoPodUrlValid(video.podUrl) && 35 isVideoDurationValid(video.duration) &&
37 isVideoTagsValid(video.tags) && 36 isVideoMagnetUriValid(video.magnetUri) &&
38 isVideoThumbnailValid(video.thumbnailBase64) 37 isVideoNameValid(video.name) &&
39 }) 38 isVideoPodUrlValid(video.podUrl) &&
40} 39 isVideoTagsValid(video.tags) &&
41 40 isVideoThumbnailValid(video.thumbnailBase64)
42function isEachRemoveRemoteVideosValid (videos) { 41 ) ||
43 return videos.every(function (video) { 42 (
44 return isVideoMagnetUriValid(video.magnetUri) 43 isRequestTypeRemoveValid(request.type) &&
44 isVideoNameValid(video.name) &&
45 isVideoMagnetUriValid(video.magnetUri)
46 )
45 }) 47 })
46} 48}
47 49
@@ -49,6 +51,14 @@ function isArray (value) {
49 return Array.isArray(value) 51 return Array.isArray(value)
50} 52}
51 53
54function isRequestTypeAddValid (value) {
55 return value === 'add'
56}
57
58function isRequestTypeRemoveValid (value) {
59 return value === 'remove'
60}
61
52function isVideoAuthorValid (value) { 62function isVideoAuthorValid (value) {
53 return validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.AUTHOR) 63 return validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.AUTHOR)
54} 64}