diff options
Diffstat (limited to 'server/helpers/custom-validators/remote')
-rw-r--r-- | server/helpers/custom-validators/remote/videos.js | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/server/helpers/custom-validators/remote/videos.js b/server/helpers/custom-validators/remote/videos.js index 2e9cf822e..c1786014d 100644 --- a/server/helpers/custom-validators/remote/videos.js +++ b/server/helpers/custom-validators/remote/videos.js | |||
@@ -1,6 +1,7 @@ | |||
1 | 'use strict' | 1 | 'use strict' |
2 | 2 | ||
3 | const has = require('lodash/has') | 3 | const has = require('lodash/has') |
4 | const values = require('lodash/values') | ||
4 | 5 | ||
5 | const constants = require('../../../initializers/constants') | 6 | const constants = require('../../../initializers/constants') |
6 | const videosValidators = require('../videos') | 7 | const videosValidators = require('../videos') |
@@ -10,13 +11,17 @@ const ENDPOINT_ACTIONS = constants.REQUEST_ENDPOINT_ACTIONS[constants.REQUEST_EN | |||
10 | 11 | ||
11 | const remoteVideosValidators = { | 12 | const remoteVideosValidators = { |
12 | isEachRemoteRequestVideosValid, | 13 | isEachRemoteRequestVideosValid, |
13 | isEachRemoteRequestVideosQaduValid | 14 | isEachRemoteRequestVideosQaduValid, |
15 | isEachRemoteRequestVideosEventsValid | ||
14 | } | 16 | } |
15 | 17 | ||
16 | function isEachRemoteRequestVideosValid (requests) { | 18 | function isEachRemoteRequestVideosValid (requests) { |
17 | return miscValidators.isArray(requests) && | 19 | return miscValidators.isArray(requests) && |
18 | requests.every(function (request) { | 20 | requests.every(function (request) { |
19 | const video = request.data | 21 | const video = request.data |
22 | |||
23 | if (!video) return false | ||
24 | |||
20 | return ( | 25 | return ( |
21 | isRequestTypeAddValid(request.type) && | 26 | isRequestTypeAddValid(request.type) && |
22 | isCommonVideoAttributesValid(video) && | 27 | isCommonVideoAttributesValid(video) && |
@@ -45,6 +50,8 @@ function isEachRemoteRequestVideosQaduValid (requests) { | |||
45 | requests.every(function (request) { | 50 | requests.every(function (request) { |
46 | const video = request.data | 51 | const video = request.data |
47 | 52 | ||
53 | if (!video) return false | ||
54 | |||
48 | return ( | 55 | return ( |
49 | videosValidators.isVideoRemoteIdValid(video.remoteId) && | 56 | videosValidators.isVideoRemoteIdValid(video.remoteId) && |
50 | (has(video, 'views') === false || videosValidators.isVideoViewsValid) && | 57 | (has(video, 'views') === false || videosValidators.isVideoViewsValid) && |
@@ -54,6 +61,21 @@ function isEachRemoteRequestVideosQaduValid (requests) { | |||
54 | }) | 61 | }) |
55 | } | 62 | } |
56 | 63 | ||
64 | function isEachRemoteRequestVideosEventsValid (requests) { | ||
65 | return miscValidators.isArray(requests) && | ||
66 | requests.every(function (request) { | ||
67 | const eventData = request.data | ||
68 | |||
69 | if (!eventData) return false | ||
70 | |||
71 | return ( | ||
72 | videosValidators.isVideoRemoteIdValid(eventData.remoteId) && | ||
73 | values(constants.REQUEST_VIDEO_EVENT_TYPES).indexOf(eventData.eventType) !== -1 && | ||
74 | videosValidators.isVideoEventCountValid(eventData.count) | ||
75 | ) | ||
76 | }) | ||
77 | } | ||
78 | |||
57 | // --------------------------------------------------------------------------- | 79 | // --------------------------------------------------------------------------- |
58 | 80 | ||
59 | module.exports = remoteVideosValidators | 81 | module.exports = remoteVideosValidators |