diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-01-31 11:23:52 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-01-31 11:23:52 +0100 |
commit | c45f7f84001c2731909db04dd82e1c1f290386eb (patch) | |
tree | b7e57420a1f65dfbbacc1a532bf489c9bea6125d /middlewares/reqValidators/videos.js | |
parent | cda021079ff455cc0fd0eb95a5395fa808ab63d1 (diff) | |
download | PeerTube-c45f7f84001c2731909db04dd82e1c1f290386eb.tar.gz PeerTube-c45f7f84001c2731909db04dd82e1c1f290386eb.tar.zst PeerTube-c45f7f84001c2731909db04dd82e1c1f290386eb.zip |
Infile code reorganization
Diffstat (limited to 'middlewares/reqValidators/videos.js')
-rw-r--r-- | middlewares/reqValidators/videos.js | 51 |
1 files changed, 30 insertions, 21 deletions
diff --git a/middlewares/reqValidators/videos.js b/middlewares/reqValidators/videos.js index a34445f7a..3479c47c3 100644 --- a/middlewares/reqValidators/videos.js +++ b/middlewares/reqValidators/videos.js | |||
@@ -2,28 +2,17 @@ | |||
2 | 'use strict' | 2 | 'use strict' |
3 | 3 | ||
4 | var checkErrors = require('./utils').checkErrors | 4 | var checkErrors = require('./utils').checkErrors |
5 | var VideosDB = require('../../initializers/database').VideosDB | ||
6 | var logger = require('../../helpers/logger') | 5 | var logger = require('../../helpers/logger') |
6 | var VideosDB = require('../../initializers/database').VideosDB | ||
7 | 7 | ||
8 | var videos = {} | 8 | var reqValidatorsVideos = { |
9 | 9 | videosAdd: videosAdd, | |
10 | function findVideoById (id, callback) { | 10 | videosGet: videosGet, |
11 | VideosDB.findById(id, { _id: 1, namePath: 1 }).limit(1).exec(function (err, video) { | 11 | videosRemove: videosRemove, |
12 | if (err) throw err | 12 | videosSearch: videosSearch |
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 | } | 13 | } |
25 | 14 | ||
26 | videos.videosAdd = function (req, res, next) { | 15 | function videosAdd (req, res, next) { |
27 | req.checkFiles('input_video[0].originalname', 'Should have an input video').notEmpty() | 16 | req.checkFiles('input_video[0].originalname', 'Should have an input video').notEmpty() |
28 | req.checkFiles('input_video[0].mimetype', 'Should have a correct mime type').matches(/video\/(webm)|(mp4)|(ogg)/i) | 17 | req.checkFiles('input_video[0].mimetype', 'Should have a correct mime type').matches(/video\/(webm)|(mp4)|(ogg)/i) |
29 | req.checkBody('name', 'Should have a name').isLength(1, 50) | 18 | req.checkBody('name', 'Should have a name').isLength(1, 50) |
@@ -34,7 +23,7 @@ | |||
34 | checkErrors(req, res, next) | 23 | checkErrors(req, res, next) |
35 | } | 24 | } |
36 | 25 | ||
37 | videos.videosGet = function (req, res, next) { | 26 | function videosGet (req, res, next) { |
38 | req.checkParams('id', 'Should have a valid id').notEmpty().isMongoId() | 27 | req.checkParams('id', 'Should have a valid id').notEmpty().isMongoId() |
39 | 28 | ||
40 | logger.debug('Checking videosGet parameters', { parameters: req.params }) | 29 | logger.debug('Checking videosGet parameters', { parameters: req.params }) |
@@ -48,7 +37,7 @@ | |||
48 | }) | 37 | }) |
49 | } | 38 | } |
50 | 39 | ||
51 | videos.videosRemove = function (req, res, next) { | 40 | function videosRemove (req, res, next) { |
52 | req.checkParams('id', 'Should have a valid id').notEmpty().isMongoId() | 41 | req.checkParams('id', 'Should have a valid id').notEmpty().isMongoId() |
53 | 42 | ||
54 | logger.debug('Checking videosRemove parameters', { parameters: req.params }) | 43 | logger.debug('Checking videosRemove parameters', { parameters: req.params }) |
@@ -63,5 +52,25 @@ | |||
63 | }) | 52 | }) |
64 | } | 53 | } |
65 | 54 | ||
66 | module.exports = videos | 55 | function videosSearch (req, res, next) { |
56 | req.checkParams('name', 'Should have a name').notEmpty() | ||
57 | |||
58 | logger.debug('Checking videosSearch parameters', { parameters: req.params }) | ||
59 | |||
60 | checkErrors(req, res, next) | ||
61 | } | ||
62 | |||
63 | // --------------------------------------------------------------------------- | ||
64 | |||
65 | module.exports = reqValidatorsVideos | ||
66 | |||
67 | // --------------------------------------------------------------------------- | ||
68 | |||
69 | function findVideoById (id, callback) { | ||
70 | VideosDB.findById(id, { _id: 1, namePath: 1 }).limit(1).exec(function (err, video) { | ||
71 | if (err) throw err | ||
72 | |||
73 | callback(video) | ||
74 | }) | ||
75 | } | ||
67 | })() | 76 | })() |