aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers')
-rw-r--r--server/helpers/custom-validators/remote/videos.js25
-rw-r--r--server/helpers/custom-validators/videos.js17
-rw-r--r--server/helpers/requests.js2
3 files changed, 39 insertions, 5 deletions
diff --git a/server/helpers/custom-validators/remote/videos.js b/server/helpers/custom-validators/remote/videos.js
index ee68ebc10..2e9cf822e 100644
--- a/server/helpers/custom-validators/remote/videos.js
+++ b/server/helpers/custom-validators/remote/videos.js
@@ -1,5 +1,7 @@
1'use strict' 1'use strict'
2 2
3const has = require('lodash/has')
4
3const constants = require('../../../initializers/constants') 5const constants = require('../../../initializers/constants')
4const videosValidators = require('../videos') 6const videosValidators = require('../videos')
5const miscValidators = require('../misc') 7const miscValidators = require('../misc')
@@ -7,7 +9,8 @@ const miscValidators = require('../misc')
7const ENDPOINT_ACTIONS = constants.REQUEST_ENDPOINT_ACTIONS[constants.REQUEST_ENDPOINTS.VIDEOS] 9const ENDPOINT_ACTIONS = constants.REQUEST_ENDPOINT_ACTIONS[constants.REQUEST_ENDPOINTS.VIDEOS]
8 10
9const remoteVideosValidators = { 11const remoteVideosValidators = {
10 isEachRemoteRequestVideosValid 12 isEachRemoteRequestVideosValid,
13 isEachRemoteRequestVideosQaduValid
11} 14}
12 15
13function isEachRemoteRequestVideosValid (requests) { 16function isEachRemoteRequestVideosValid (requests) {
@@ -16,13 +19,13 @@ function isEachRemoteRequestVideosValid (requests) {
16 const video = request.data 19 const video = request.data
17 return ( 20 return (
18 isRequestTypeAddValid(request.type) && 21 isRequestTypeAddValid(request.type) &&
19 isCommonVideoAttrbiutesValid(video) && 22 isCommonVideoAttributesValid(video) &&
20 videosValidators.isVideoAuthorValid(video.author) && 23 videosValidators.isVideoAuthorValid(video.author) &&
21 videosValidators.isVideoThumbnailDataValid(video.thumbnailData) 24 videosValidators.isVideoThumbnailDataValid(video.thumbnailData)
22 ) || 25 ) ||
23 ( 26 (
24 isRequestTypeUpdateValid(request.type) && 27 isRequestTypeUpdateValid(request.type) &&
25 isCommonVideoAttrbiutesValid(video) 28 isCommonVideoAttributesValid(video)
26 ) || 29 ) ||
27 ( 30 (
28 isRequestTypeRemoveValid(request.type) && 31 isRequestTypeRemoveValid(request.type) &&
@@ -37,13 +40,27 @@ function isEachRemoteRequestVideosValid (requests) {
37 }) 40 })
38} 41}
39 42
43function isEachRemoteRequestVideosQaduValid (requests) {
44 return miscValidators.isArray(requests) &&
45 requests.every(function (request) {
46 const video = request.data
47
48 return (
49 videosValidators.isVideoRemoteIdValid(video.remoteId) &&
50 (has(video, 'views') === false || videosValidators.isVideoViewsValid) &&
51 (has(video, 'likes') === false || videosValidators.isVideoLikesValid) &&
52 (has(video, 'dislikes') === false || videosValidators.isVideoDislikesValid)
53 )
54 })
55}
56
40// --------------------------------------------------------------------------- 57// ---------------------------------------------------------------------------
41 58
42module.exports = remoteVideosValidators 59module.exports = remoteVideosValidators
43 60
44// --------------------------------------------------------------------------- 61// ---------------------------------------------------------------------------
45 62
46function isCommonVideoAttrbiutesValid (video) { 63function isCommonVideoAttributesValid (video) {
47 return videosValidators.isVideoDateValid(video.createdAt) && 64 return videosValidators.isVideoDateValid(video.createdAt) &&
48 videosValidators.isVideoDateValid(video.updatedAt) && 65 videosValidators.isVideoDateValid(video.updatedAt) &&
49 videosValidators.isVideoDescriptionValid(video.description) && 66 videosValidators.isVideoDescriptionValid(video.description) &&
diff --git a/server/helpers/custom-validators/videos.js b/server/helpers/custom-validators/videos.js
index e2d2c8e6d..1d844118b 100644
--- a/server/helpers/custom-validators/videos.js
+++ b/server/helpers/custom-validators/videos.js
@@ -22,7 +22,10 @@ const videosValidators = {
22 isVideoRemoteIdValid, 22 isVideoRemoteIdValid,
23 isVideoAbuseReasonValid, 23 isVideoAbuseReasonValid,
24 isVideoAbuseReporterUsernameValid, 24 isVideoAbuseReporterUsernameValid,
25 isVideoFile 25 isVideoFile,
26 isVideoViewsValid,
27 isVideoLikesValid,
28 isVideoDislikesValid
26} 29}
27 30
28function isVideoAuthorValid (value) { 31function isVideoAuthorValid (value) {
@@ -82,6 +85,18 @@ function isVideoAbuseReporterUsernameValid (value) {
82 return usersValidators.isUserUsernameValid(value) 85 return usersValidators.isUserUsernameValid(value)
83} 86}
84 87
88function isVideoViewsValid (value) {
89 return validator.isInt(value, { min: 0 })
90}
91
92function isVideoLikesValid (value) {
93 return validator.isInt(value, { min: 0 })
94}
95
96function isVideoDislikesValid (value) {
97 return validator.isInt(value, { min: 0 })
98}
99
85function isVideoFile (value, files) { 100function isVideoFile (value, files) {
86 // Should have files 101 // Should have files
87 if (!files) return false 102 if (!files) return false
diff --git a/server/helpers/requests.js b/server/helpers/requests.js
index 095b95e1c..427864117 100644
--- a/server/helpers/requests.js
+++ b/server/helpers/requests.js
@@ -58,6 +58,8 @@ function makeSecureRequest (params, callback) {
58 requestParams.json.data = params.data 58 requestParams.json.data = params.data
59 } 59 }
60 60
61 console.log(requestParams.json.data)
62
61 request.post(requestParams, callback) 63 request.post(requestParams, callback)
62} 64}
63 65