diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-01-17 20:59:16 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-01-17 20:59:16 +0100 |
commit | da691c46df2f3c542d4fffaaa99ef18b6ef71f53 (patch) | |
tree | e6ce2dd25bc66e6268e839e96009576f4038758b /server/helpers/custom-validators/remote | |
parent | 62f4ef413c8ef4269e7cdc21dea0e99ab2191201 (diff) | |
download | PeerTube-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.js | 45 |
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 | ||
3 | const constants = require('../../../initializers/constants') | ||
3 | const videosValidators = require('../videos') | 4 | const videosValidators = require('../videos') |
4 | const miscValidators = require('../misc') | 5 | const miscValidators = require('../misc') |
5 | 6 | ||
7 | const ENDPOINT_ACTIONS = constants.REQUEST_ENDPOINT_ACTIONS[constants.REQUEST_ENDPOINTS.VIDEOS] | ||
8 | |||
6 | const remoteVideosValidators = { | 9 | const 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 | ||
46 | function 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 | |||
59 | function isRequestTypeAddValid (value) { | 58 | function isRequestTypeAddValid (value) { |
60 | return value === 'add' | 59 | return value === ENDPOINT_ACTIONS.ADD |
61 | } | 60 | } |
62 | 61 | ||
63 | function isRequestTypeUpdateValid (value) { | 62 | function isRequestTypeUpdateValid (value) { |
64 | return value === 'update' | 63 | return value === ENDPOINT_ACTIONS.UPDATE |
65 | } | 64 | } |
66 | 65 | ||
67 | function isRequestTypeRemoveValid (value) { | 66 | function isRequestTypeRemoveValid (value) { |
68 | return value === 'remove' | 67 | return value === ENDPOINT_ACTIONS.REMOVE |
69 | } | 68 | } |
70 | 69 | ||
71 | function isRequestTypeReportAbuseValid (value) { | 70 | function isRequestTypeReportAbuseValid (value) { |
72 | return value === 'report-abuse' | 71 | return value === ENDPOINT_ACTIONS.REPORT_ABUSE |
73 | } | 72 | } |