aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers')
-rw-r--r--server/helpers/custom-validators/remote/videos.js24
-rw-r--r--server/helpers/custom-validators/videos.js14
-rw-r--r--server/helpers/utils.js7
3 files changed, 40 insertions, 5 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
3const has = require('lodash/has') 3const has = require('lodash/has')
4const values = require('lodash/values')
4 5
5const constants = require('../../../initializers/constants') 6const constants = require('../../../initializers/constants')
6const videosValidators = require('../videos') 7const videosValidators = require('../videos')
@@ -10,13 +11,17 @@ const ENDPOINT_ACTIONS = constants.REQUEST_ENDPOINT_ACTIONS[constants.REQUEST_EN
10 11
11const remoteVideosValidators = { 12const remoteVideosValidators = {
12 isEachRemoteRequestVideosValid, 13 isEachRemoteRequestVideosValid,
13 isEachRemoteRequestVideosQaduValid 14 isEachRemoteRequestVideosQaduValid,
15 isEachRemoteRequestVideosEventsValid
14} 16}
15 17
16function isEachRemoteRequestVideosValid (requests) { 18function 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
64function 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
59module.exports = remoteVideosValidators 81module.exports = remoteVideosValidators
diff --git a/server/helpers/custom-validators/videos.js b/server/helpers/custom-validators/videos.js
index 1d844118b..c5a1f3cb5 100644
--- a/server/helpers/custom-validators/videos.js
+++ b/server/helpers/custom-validators/videos.js
@@ -7,6 +7,7 @@ const 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 9const VIDEO_ABUSES_CONSTRAINTS_FIELDS = constants.CONSTRAINTS_FIELDS.VIDEO_ABUSES
10const VIDEO_EVENTS_CONSTRAINTS_FIELDS = constants.CONSTRAINTS_FIELDS.VIDEO_EVENTS
10 11
11const videosValidators = { 12const videosValidators = {
12 isVideoAuthorValid, 13 isVideoAuthorValid,
@@ -25,7 +26,8 @@ const videosValidators = {
25 isVideoFile, 26 isVideoFile,
26 isVideoViewsValid, 27 isVideoViewsValid,
27 isVideoLikesValid, 28 isVideoLikesValid,
28 isVideoDislikesValid 29 isVideoDislikesValid,
30 isVideoEventCountValid
29} 31}
30 32
31function isVideoAuthorValid (value) { 33function isVideoAuthorValid (value) {
@@ -86,15 +88,19 @@ function isVideoAbuseReporterUsernameValid (value) {
86} 88}
87 89
88function isVideoViewsValid (value) { 90function isVideoViewsValid (value) {
89 return validator.isInt(value, { min: 0 }) 91 return validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.VIEWS)
90} 92}
91 93
92function isVideoLikesValid (value) { 94function isVideoLikesValid (value) {
93 return validator.isInt(value, { min: 0 }) 95 return validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.LIKES)
94} 96}
95 97
96function isVideoDislikesValid (value) { 98function isVideoDislikesValid (value) {
97 return validator.isInt(value, { min: 0 }) 99 return validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.DISLIKES)
100}
101
102function isVideoEventCountValid (value) {
103 return validator.isInt(value + '', VIDEO_EVENTS_CONSTRAINTS_FIELDS.COUNT)
98} 104}
99 105
100function isVideoFile (value, files) { 106function isVideoFile (value, files) {
diff --git a/server/helpers/utils.js b/server/helpers/utils.js
index 9f4b14582..6d40e8f3f 100644
--- a/server/helpers/utils.js
+++ b/server/helpers/utils.js
@@ -6,6 +6,7 @@ const logger = require('./logger')
6 6
7const utils = { 7const utils = {
8 badRequest, 8 badRequest,
9 createEmptyCallback,
9 cleanForExit, 10 cleanForExit,
10 generateRandomString, 11 generateRandomString,
11 isTestInstance, 12 isTestInstance,
@@ -29,6 +30,12 @@ function cleanForExit (webtorrentProcess) {
29 process.kill(-webtorrentProcess.pid) 30 process.kill(-webtorrentProcess.pid)
30} 31}
31 32
33function createEmptyCallback () {
34 return function (err) {
35 if (err) logger.error('Error in empty callback.', { error: err })
36 }
37}
38
32function isTestInstance () { 39function isTestInstance () {
33 return (process.env.NODE_ENV === 'test') 40 return (process.env.NODE_ENV === 'test')
34} 41}