aboutsummaryrefslogtreecommitdiffhomepage
path: root/middlewares/reqValidators/videos.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2015-11-07 14:16:26 +0100
committerChocobozzz <florian.bigard@gmail.com>2015-11-07 14:16:26 +0100
commit34ca3b5225479a5da986c86ee4c42a73ae6df5ad (patch)
tree561ba5ae1adccd5729305a8cc17d13d24a0c2ddb /middlewares/reqValidators/videos.js
parentf5a60a5138135a3412dfbcfd6e564f7aa47a55c2 (diff)
downloadPeerTube-34ca3b5225479a5da986c86ee4c42a73ae6df5ad.tar.gz
PeerTube-34ca3b5225479a5da986c86ee4c42a73ae6df5ad.tar.zst
PeerTube-34ca3b5225479a5da986c86ee4c42a73ae6df5ad.zip
Add requests parameters validations
Diffstat (limited to 'middlewares/reqValidators/videos.js')
-rw-r--r--middlewares/reqValidators/videos.js67
1 files changed, 67 insertions, 0 deletions
diff --git a/middlewares/reqValidators/videos.js b/middlewares/reqValidators/videos.js
new file mode 100644
index 000000000..3763a657c
--- /dev/null
+++ b/middlewares/reqValidators/videos.js
@@ -0,0 +1,67 @@
1;(function () {
2 'use strict'
3
4 var checkErrors = require('./utils').checkErrors
5 var VideosDB = require('../../src/database').VideosDB
6 var logger = require('../../src/logger')
7
8 var videos = {}
9
10 function findVideoById (id, callback) {
11 VideosDB.findById(id, { _id: 1, namePath: 1 }).limit(1).exec(function (err, video) {
12 if (err) throw err
13
14 callback(video)
15 })
16 }
17
18 videos.videosSearch = function (req, res, next) {
19 req.checkParams('name', 'Should have a name').notEmpty()
20
21 logger.debug('Checking videosSearch parameters', { parameters: req.params })
22
23 checkErrors(req, res, next)
24 }
25
26 videos.videosAdd = function (req, res, next) {
27 req.checkFiles('input_video.originalname', 'Should have an input video').notEmpty()
28 req.checkFiles('input_video.mimetype', 'Should have a correct mime type').matches(/video\/(webm)|(mp4)|(ogg)/i)
29 req.checkBody('name', 'Should have a name').isLength(1, 50)
30 req.checkBody('description', 'Should have a description').isLength(1, 250)
31
32 logger.debug('Checking videosAdd parameters', { parameters: req.body, files: req.files })
33
34 checkErrors(req, res, next)
35 }
36
37 videos.videosGet = function (req, res, next) {
38 req.checkParams('id', 'Should have a valid id').notEmpty().isMongoId()
39
40 logger.debug('Checking videosGet parameters', { parameters: req.params })
41
42 checkErrors(req, res, function () {
43 findVideoById(req.params.id, function (video) {
44 if (!video) return res.status(404).send('Video not found')
45
46 next()
47 })
48 })
49 }
50
51 videos.videosRemove = function (req, res, next) {
52 req.checkParams('id', 'Should have a valid id').notEmpty().isMongoId()
53
54 logger.debug('Checking videosRemove parameters', { parameters: req.params })
55
56 checkErrors(req, res, function () {
57 findVideoById(req.params.id, function (video) {
58 if (!video) return res.status(404).send('Video not found')
59 else if (video.namePath === null) return res.status(403).send('Cannot remove video of another pod')
60
61 next()
62 })
63 })
64 }
65
66 module.exports = videos
67})()