diff options
Diffstat (limited to 'server/helpers/custom-validators/videos.js')
-rw-r--r-- | server/helpers/custom-validators/videos.js | 71 |
1 files changed, 23 insertions, 48 deletions
diff --git a/server/helpers/custom-validators/videos.js b/server/helpers/custom-validators/videos.js index 1a7753265..7f727854d 100644 --- a/server/helpers/custom-validators/videos.js +++ b/server/helpers/custom-validators/videos.js | |||
@@ -6,43 +6,22 @@ const constants = require('../../initializers/constants') | |||
6 | const usersValidators = require('./users') | 6 | const usersValidators = require('./users') |
7 | const miscValidators = require('./misc') | 7 | const miscValidators = require('./misc') |
8 | const VIDEOS_CONSTRAINTS_FIELDS = constants.CONSTRAINTS_FIELDS.VIDEOS | 8 | const VIDEOS_CONSTRAINTS_FIELDS = constants.CONSTRAINTS_FIELDS.VIDEOS |
9 | const VIDEO_ABUSES_CONSTRAINTS_FIELDS = constants.CONSTRAINTS_FIELDS.VIDEO_ABUSES | ||
9 | 10 | ||
10 | const videosValidators = { | 11 | const videosValidators = { |
11 | isEachRemoteVideosValid, | ||
12 | isVideoAuthorValid, | 12 | isVideoAuthorValid, |
13 | isVideoDateValid, | 13 | isVideoDateValid, |
14 | isVideoDescriptionValid, | 14 | isVideoDescriptionValid, |
15 | isVideoDurationValid, | 15 | isVideoDurationValid, |
16 | isVideoMagnetValid, | 16 | isVideoInfoHashValid, |
17 | isVideoNameValid, | 17 | isVideoNameValid, |
18 | isVideoPodHostValid, | ||
19 | isVideoTagsValid, | 18 | isVideoTagsValid, |
20 | isVideoThumbnailValid, | 19 | isVideoThumbnailValid, |
21 | isVideoThumbnail64Valid | 20 | isVideoThumbnailDataValid, |
22 | } | 21 | isVideoExtnameValid, |
23 | 22 | isVideoRemoteIdValid, | |
24 | function isEachRemoteVideosValid (requests) { | 23 | isVideoAbuseReasonValid, |
25 | return miscValidators.isArray(requests) && | 24 | isVideoAbuseReporterUsernameValid |
26 | requests.every(function (request) { | ||
27 | const video = request.data | ||
28 | return ( | ||
29 | isRequestTypeAddValid(request.type) && | ||
30 | isVideoAuthorValid(video.author) && | ||
31 | isVideoDateValid(video.createdDate) && | ||
32 | isVideoDescriptionValid(video.description) && | ||
33 | isVideoDurationValid(video.duration) && | ||
34 | isVideoMagnetValid(video.magnet) && | ||
35 | isVideoNameValid(video.name) && | ||
36 | isVideoTagsValid(video.tags) && | ||
37 | isVideoThumbnail64Valid(video.thumbnailBase64) && | ||
38 | isVideoRemoteIdValid(video.remoteId) | ||
39 | ) || | ||
40 | ( | ||
41 | isRequestTypeRemoveValid(request.type) && | ||
42 | isVideoNameValid(video.name) && | ||
43 | isVideoRemoteIdValid(video.remoteId) | ||
44 | ) | ||
45 | }) | ||
46 | } | 25 | } |
47 | 26 | ||
48 | function isVideoAuthorValid (value) { | 27 | function isVideoAuthorValid (value) { |
@@ -61,17 +40,16 @@ function isVideoDurationValid (value) { | |||
61 | return validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.DURATION) | 40 | return validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.DURATION) |
62 | } | 41 | } |
63 | 42 | ||
64 | function isVideoMagnetValid (value) { | 43 | function isVideoExtnameValid (value) { |
65 | return validator.isLength(value.infoHash, VIDEOS_CONSTRAINTS_FIELDS.MAGNET.INFO_HASH) | 44 | return VIDEOS_CONSTRAINTS_FIELDS.EXTNAME.indexOf(value) !== -1 |
66 | } | 45 | } |
67 | 46 | ||
68 | function isVideoNameValid (value) { | 47 | function isVideoInfoHashValid (value) { |
69 | return validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.NAME) | 48 | return validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.INFO_HASH) |
70 | } | 49 | } |
71 | 50 | ||
72 | function isVideoPodHostValid (value) { | 51 | function isVideoNameValid (value) { |
73 | // TODO: set options (TLD...) | 52 | return validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.NAME) |
74 | return validator.isURL(value) | ||
75 | } | 53 | } |
76 | 54 | ||
77 | function isVideoTagsValid (tags) { | 55 | function isVideoTagsValid (tags) { |
@@ -87,25 +65,22 @@ function isVideoThumbnailValid (value) { | |||
87 | return validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.THUMBNAIL) | 65 | return validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.THUMBNAIL) |
88 | } | 66 | } |
89 | 67 | ||
90 | function isVideoThumbnail64Valid (value) { | 68 | function isVideoThumbnailDataValid (value) { |
91 | return validator.isBase64(value) && | 69 | return validator.isByteLength(value, VIDEOS_CONSTRAINTS_FIELDS.THUMBNAIL_DATA) |
92 | validator.isByteLength(value, VIDEOS_CONSTRAINTS_FIELDS.THUMBNAIL64) | ||
93 | } | 70 | } |
94 | 71 | ||
95 | function isVideoRemoteIdValid (value) { | 72 | function isVideoRemoteIdValid (value) { |
96 | return validator.isMongoId(value) | 73 | return validator.isUUID(value, 4) |
97 | } | 74 | } |
98 | 75 | ||
99 | // --------------------------------------------------------------------------- | 76 | function isVideoAbuseReasonValid (value) { |
77 | return validator.isLength(value, VIDEO_ABUSES_CONSTRAINTS_FIELDS.REASON) | ||
78 | } | ||
100 | 79 | ||
101 | module.exports = videosValidators | 80 | function isVideoAbuseReporterUsernameValid (value) { |
81 | return usersValidators.isUserUsernameValid(value) | ||
82 | } | ||
102 | 83 | ||
103 | // --------------------------------------------------------------------------- | 84 | // --------------------------------------------------------------------------- |
104 | 85 | ||
105 | function isRequestTypeAddValid (value) { | 86 | module.exports = videosValidators |
106 | return value === 'add' | ||
107 | } | ||
108 | |||
109 | function isRequestTypeRemoveValid (value) { | ||
110 | return value === 'remove' | ||
111 | } | ||