aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-02-10 11:27:14 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-02-10 11:27:14 +0100
commitf6f7dfee01e8b7ddf62d2549b8f381d0b12b590e (patch)
treedf99579a701d40b02e495c76337a6d266f60dcc6 /server
parentc70e0710b39b45e1b8b2d043e3d94f59df16b8a8 (diff)
downloadPeerTube-f6f7dfee01e8b7ddf62d2549b8f381d0b12b590e.tar.gz
PeerTube-f6f7dfee01e8b7ddf62d2549b8f381d0b12b590e.tar.zst
PeerTube-f6f7dfee01e8b7ddf62d2549b8f381d0b12b590e.zip
Server: update express-validator
Diffstat (limited to 'server')
-rw-r--r--server/helpers/custom-validators/videos.js18
-rw-r--r--server/middlewares/validators/videos.js4
2 files changed, 18 insertions, 4 deletions
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()