aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators/videos.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/custom-validators/videos.js')
-rw-r--r--server/helpers/custom-validators/videos.js71
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')
6const usersValidators = require('./users') 6const 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
9 10
10const videosValidators = { 11const 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,
24function 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
48function isVideoAuthorValid (value) { 27function 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
64function isVideoMagnetValid (value) { 43function 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
68function isVideoNameValid (value) { 47function 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
72function isVideoPodHostValid (value) { 51function 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
77function isVideoTagsValid (tags) { 55function 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
90function isVideoThumbnail64Valid (value) { 68function 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
95function isVideoRemoteIdValid (value) { 72function isVideoRemoteIdValid (value) {
96 return validator.isMongoId(value) 73 return validator.isUUID(value, 4)
97} 74}
98 75
99// --------------------------------------------------------------------------- 76function isVideoAbuseReasonValid (value) {
77 return validator.isLength(value, VIDEO_ABUSES_CONSTRAINTS_FIELDS.REASON)
78}
100 79
101module.exports = videosValidators 80function isVideoAbuseReporterUsernameValid (value) {
81 return usersValidators.isUserUsernameValid(value)
82}
102 83
103// --------------------------------------------------------------------------- 84// ---------------------------------------------------------------------------
104 85
105function isRequestTypeAddValid (value) { 86module.exports = videosValidators
106 return value === 'add'
107}
108
109function isRequestTypeRemoveValid (value) {
110 return value === 'remove'
111}