aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--package.json2
-rw-r--r--server/helpers/custom-validators/videos.js18
-rw-r--r--server/middlewares/validators/videos.js4
3 files changed, 19 insertions, 5 deletions
diff --git a/package.json b/package.json
index 0d650ddeb..4197f919a 100644
--- a/package.json
+++ b/package.json
@@ -51,7 +51,7 @@
51 "dezalgo": "^1.0.3", 51 "dezalgo": "^1.0.3",
52 "express": "^4.12.4", 52 "express": "^4.12.4",
53 "express-oauth-server": "https://github.com/Chocobozzz/express-oauth-server", 53 "express-oauth-server": "https://github.com/Chocobozzz/express-oauth-server",
54 "express-validator": "^2.11.0", 54 "express-validator": "^3.1.0",
55 "fluent-ffmpeg": "^2.1.0", 55 "fluent-ffmpeg": "^2.1.0",
56 "js-yaml": "^3.5.4", 56 "js-yaml": "^3.5.4",
57 "lodash": "^4.11.1", 57 "lodash": "^4.11.1",
diff --git a/server/helpers/custom-validators/videos.js b/server/helpers/custom-validators/videos.js
index 7f727854d..e2d2c8e6d 100644
--- a/server/helpers/custom-validators/videos.js
+++ b/server/helpers/custom-validators/videos.js
@@ -21,7 +21,8 @@ const videosValidators = {
21 isVideoExtnameValid, 21 isVideoExtnameValid,
22 isVideoRemoteIdValid, 22 isVideoRemoteIdValid,
23 isVideoAbuseReasonValid, 23 isVideoAbuseReasonValid,
24 isVideoAbuseReporterUsernameValid 24 isVideoAbuseReporterUsernameValid,
25 isVideoFile
25} 26}
26 27
27function isVideoAuthorValid (value) { 28function isVideoAuthorValid (value) {
@@ -81,6 +82,21 @@ function isVideoAbuseReporterUsernameValid (value) {
81 return usersValidators.isUserUsernameValid(value) 82 return usersValidators.isUserUsernameValid(value)
82} 83}
83 84
85function isVideoFile (value, files) {
86 // Should have files
87 if (!files) return false
88
89 // Should have videofile file
90 const videofile = files.videofile
91 if (!videofile || videofile.length === 0) return false
92
93 // The file should exist
94 const file = videofile[0]
95 if (!file || !file.originalname) return false
96
97 return new RegExp('^video/(webm|mp4|ogg)$', 'i').test(file.mimetype)
98}
99
84// --------------------------------------------------------------------------- 100// ---------------------------------------------------------------------------
85 101
86module.exports = videosValidators 102module.exports = videosValidators
diff --git a/server/middlewares/validators/videos.js b/server/middlewares/validators/videos.js
index 4fe6dcd8b..5c3f3ecf3 100644
--- a/server/middlewares/validators/videos.js
+++ b/server/middlewares/validators/videos.js
@@ -17,9 +17,7 @@ const validatorsVideos = {
17} 17}
18 18
19function videosAdd (req, res, next) { 19function videosAdd (req, res, next) {
20 req.checkFiles('videofile[0].originalname', 'Should have an input video').notEmpty() 20 req.checkBody('videofile', 'Should have a valid file').isVideoFile(req.files)
21 // TODO: move to constants and function
22 req.checkFiles('videofile[0].mimetype', 'Should have a correct mime type').matches(/video\/(webm)|(mp4)|(ogg)/i)
23 req.checkBody('name', 'Should have a valid name').isVideoNameValid() 21 req.checkBody('name', 'Should have a valid name').isVideoNameValid()
24 req.checkBody('description', 'Should have a valid description').isVideoDescriptionValid() 22 req.checkBody('description', 'Should have a valid description').isVideoDescriptionValid()
25 req.checkBody('tags', 'Should have correct tags').isVideoTagsValid() 23 req.checkBody('tags', 'Should have correct tags').isVideoTagsValid()