diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-06-18 16:13:54 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-06-18 16:13:54 +0200 |
commit | 528a9efa8272532bbd0dafc35c3e05e57c50f61e (patch) | |
tree | 62d4417df4ab9b2e53c44dc7271be81b88e4e0e5 /server/helpers/customValidators.js | |
parent | b2e4c0ba1a33b8a50491a1f8d111468a7da5640f (diff) | |
download | PeerTube-528a9efa8272532bbd0dafc35c3e05e57c50f61e.tar.gz PeerTube-528a9efa8272532bbd0dafc35c3e05e57c50f61e.tar.zst PeerTube-528a9efa8272532bbd0dafc35c3e05e57c50f61e.zip |
Try to make a better communication (between pods) module
Diffstat (limited to 'server/helpers/customValidators.js')
-rw-r--r-- | server/helpers/customValidators.js | 48 |
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 | ||
8 | const customValidators = { | 8 | const 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 | ||
28 | function isEachAddRemoteVideosValid (videos) { | 27 | function 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) | |
42 | function 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 | ||
54 | function isRequestTypeAddValid (value) { | ||
55 | return value === 'add' | ||
56 | } | ||
57 | |||
58 | function isRequestTypeRemoveValid (value) { | ||
59 | return value === 'remove' | ||
60 | } | ||
61 | |||
52 | function isVideoAuthorValid (value) { | 62 | function isVideoAuthorValid (value) { |
53 | return validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.AUTHOR) | 63 | return validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.AUTHOR) |
54 | } | 64 | } |