aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators/remote
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-01-17 20:59:16 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-01-17 20:59:16 +0100
commitda691c46df2f3c542d4fffaaa99ef18b6ef71f53 (patch)
treee6ce2dd25bc66e6268e839e96009576f4038758b /server/helpers/custom-validators/remote
parent62f4ef413c8ef4269e7cdc21dea0e99ab2191201 (diff)
downloadPeerTube-da691c46df2f3c542d4fffaaa99ef18b6ef71f53.tar.gz
PeerTube-da691c46df2f3c542d4fffaaa99ef18b6ef71f53.tar.zst
PeerTube-da691c46df2f3c542d4fffaaa99ef18b6ef71f53.zip
Server: remote video validators refractoring
Diffstat (limited to 'server/helpers/custom-validators/remote')
-rw-r--r--server/helpers/custom-validators/remote/videos.js45
1 files changed, 22 insertions, 23 deletions
diff --git a/server/helpers/custom-validators/remote/videos.js b/server/helpers/custom-validators/remote/videos.js
index 7c27b9dbb..ee68ebc10 100644
--- a/server/helpers/custom-validators/remote/videos.js
+++ b/server/helpers/custom-validators/remote/videos.js
@@ -1,8 +1,11 @@
1'use strict' 1'use strict'
2 2
3const constants = require('../../../initializers/constants')
3const videosValidators = require('../videos') 4const videosValidators = require('../videos')
4const miscValidators = require('../misc') 5const miscValidators = require('../misc')
5 6
7const ENDPOINT_ACTIONS = constants.REQUEST_ENDPOINT_ACTIONS[constants.REQUEST_ENDPOINTS.VIDEOS]
8
6const remoteVideosValidators = { 9const remoteVideosValidators = {
7 isEachRemoteRequestVideosValid 10 isEachRemoteRequestVideosValid
8} 11}
@@ -13,29 +16,13 @@ function isEachRemoteRequestVideosValid (requests) {
13 const video = request.data 16 const video = request.data
14 return ( 17 return (
15 isRequestTypeAddValid(request.type) && 18 isRequestTypeAddValid(request.type) &&
19 isCommonVideoAttrbiutesValid(video) &&
16 videosValidators.isVideoAuthorValid(video.author) && 20 videosValidators.isVideoAuthorValid(video.author) &&
17 videosValidators.isVideoDateValid(video.createdAt) && 21 videosValidators.isVideoThumbnailDataValid(video.thumbnailData)
18 videosValidators.isVideoDateValid(video.updatedAt) &&
19 videosValidators.isVideoDescriptionValid(video.description) &&
20 videosValidators.isVideoDurationValid(video.duration) &&
21 videosValidators.isVideoInfoHashValid(video.infoHash) &&
22 videosValidators.isVideoNameValid(video.name) &&
23 videosValidators.isVideoTagsValid(video.tags) &&
24 videosValidators.isVideoThumbnailDataValid(video.thumbnailData) &&
25 videosValidators.isVideoRemoteIdValid(video.remoteId) &&
26 videosValidators.isVideoExtnameValid(video.extname)
27 ) || 22 ) ||
28 ( 23 (
29 isRequestTypeUpdateValid(request.type) && 24 isRequestTypeUpdateValid(request.type) &&
30 videosValidators.isVideoDateValid(video.createdAt) && 25 isCommonVideoAttrbiutesValid(video)
31 videosValidators.isVideoDateValid(video.updatedAt) &&
32 videosValidators.isVideoDescriptionValid(video.description) &&
33 videosValidators.isVideoDurationValid(video.duration) &&
34 videosValidators.isVideoInfoHashValid(video.infoHash) &&
35 videosValidators.isVideoNameValid(video.name) &&
36 videosValidators.isVideoTagsValid(video.tags) &&
37 videosValidators.isVideoRemoteIdValid(video.remoteId) &&
38 videosValidators.isVideoExtnameValid(video.extname)
39 ) || 26 ) ||
40 ( 27 (
41 isRequestTypeRemoveValid(request.type) && 28 isRequestTypeRemoveValid(request.type) &&
@@ -56,18 +43,30 @@ module.exports = remoteVideosValidators
56 43
57// --------------------------------------------------------------------------- 44// ---------------------------------------------------------------------------
58 45
46function isCommonVideoAttrbiutesValid (video) {
47 return videosValidators.isVideoDateValid(video.createdAt) &&
48 videosValidators.isVideoDateValid(video.updatedAt) &&
49 videosValidators.isVideoDescriptionValid(video.description) &&
50 videosValidators.isVideoDurationValid(video.duration) &&
51 videosValidators.isVideoInfoHashValid(video.infoHash) &&
52 videosValidators.isVideoNameValid(video.name) &&
53 videosValidators.isVideoTagsValid(video.tags) &&
54 videosValidators.isVideoRemoteIdValid(video.remoteId) &&
55 videosValidators.isVideoExtnameValid(video.extname)
56}
57
59function isRequestTypeAddValid (value) { 58function isRequestTypeAddValid (value) {
60 return value === 'add' 59 return value === ENDPOINT_ACTIONS.ADD
61} 60}
62 61
63function isRequestTypeUpdateValid (value) { 62function isRequestTypeUpdateValid (value) {
64 return value === 'update' 63 return value === ENDPOINT_ACTIONS.UPDATE
65} 64}
66 65
67function isRequestTypeRemoveValid (value) { 66function isRequestTypeRemoveValid (value) {
68 return value === 'remove' 67 return value === ENDPOINT_ACTIONS.REMOVE
69} 68}
70 69
71function isRequestTypeReportAbuseValid (value) { 70function isRequestTypeReportAbuseValid (value) {
72 return value === 'report-abuse' 71 return value === ENDPOINT_ACTIONS.REPORT_ABUSE
73} 72}