diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-02-04 21:10:33 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-02-04 21:10:33 +0100 |
commit | c173e56520b0fe4206b9ea8049b6add40bfeabcd (patch) | |
tree | 264c6cbf1bf81a6522685b4be5771bbeef4cd5dc /middlewares/reqValidators/videos.js | |
parent | c45f7f84001c2731909db04dd82e1c1f290386eb (diff) | |
download | PeerTube-c173e56520b0fe4206b9ea8049b6add40bfeabcd.tar.gz PeerTube-c173e56520b0fe4206b9ea8049b6add40bfeabcd.tar.zst PeerTube-c173e56520b0fe4206b9ea8049b6add40bfeabcd.zip |
Split models
Diffstat (limited to 'middlewares/reqValidators/videos.js')
-rw-r--r-- | middlewares/reqValidators/videos.js | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/middlewares/reqValidators/videos.js b/middlewares/reqValidators/videos.js index 3479c47c3..f7bd24658 100644 --- a/middlewares/reqValidators/videos.js +++ b/middlewares/reqValidators/videos.js | |||
@@ -3,7 +3,7 @@ | |||
3 | 3 | ||
4 | var checkErrors = require('./utils').checkErrors | 4 | var checkErrors = require('./utils').checkErrors |
5 | var logger = require('../../helpers/logger') | 5 | var logger = require('../../helpers/logger') |
6 | var VideosDB = require('../../initializers/database').VideosDB | 6 | var Videos = require('../../models/videos') |
7 | 7 | ||
8 | var reqValidatorsVideos = { | 8 | var reqValidatorsVideos = { |
9 | videosAdd: videosAdd, | 9 | videosAdd: videosAdd, |
@@ -29,8 +29,13 @@ | |||
29 | logger.debug('Checking videosGet parameters', { parameters: req.params }) | 29 | logger.debug('Checking videosGet parameters', { parameters: req.params }) |
30 | 30 | ||
31 | checkErrors(req, res, function () { | 31 | checkErrors(req, res, function () { |
32 | findVideoById(req.params.id, function (video) { | 32 | Videos.getVideoState(req.params.id, function (err, state) { |
33 | if (!video) return res.status(404).send('Video not found') | 33 | if (err) { |
34 | logger.error('Error in videosGet request validator.', { error: err }) | ||
35 | res.sendStatus(500) | ||
36 | } | ||
37 | |||
38 | if (state.exist === false) return res.status(404).send('Video not found') | ||
34 | 39 | ||
35 | next() | 40 | next() |
36 | }) | 41 | }) |
@@ -43,9 +48,14 @@ | |||
43 | logger.debug('Checking videosRemove parameters', { parameters: req.params }) | 48 | logger.debug('Checking videosRemove parameters', { parameters: req.params }) |
44 | 49 | ||
45 | checkErrors(req, res, function () { | 50 | checkErrors(req, res, function () { |
46 | findVideoById(req.params.id, function (video) { | 51 | Videos.getVideoState(req.params.id, function (err, state) { |
47 | if (!video) return res.status(404).send('Video not found') | 52 | if (err) { |
48 | else if (video.namePath === null) return res.status(403).send('Cannot remove video of another pod') | 53 | logger.error('Error in videosRemove request validator.', { error: err }) |
54 | res.sendStatus(500) | ||
55 | } | ||
56 | |||
57 | if (state.exist === false) return res.status(404).send('Video not found') | ||
58 | else if (state.owned === false) return res.status(403).send('Cannot remove video of another pod') | ||
49 | 59 | ||
50 | next() | 60 | next() |
51 | }) | 61 | }) |
@@ -63,14 +73,4 @@ | |||
63 | // --------------------------------------------------------------------------- | 73 | // --------------------------------------------------------------------------- |
64 | 74 | ||
65 | module.exports = reqValidatorsVideos | 75 | 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 | } | ||
76 | })() | 76 | })() |