diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-06-24 17:42:51 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-06-24 17:42:51 +0200 |
commit | aaf61f3810e6d57c5130af959bd2860df32775e7 (patch) | |
tree | 3871b20359aa56995a4b8974ae5cb6b911dd73f5 /server/middlewares | |
parent | 07d932038745e773359fa87bac6be70523f593ee (diff) | |
download | PeerTube-aaf61f3810e6d57c5130af959bd2860df32775e7.tar.gz PeerTube-aaf61f3810e6d57c5130af959bd2860df32775e7.tar.zst PeerTube-aaf61f3810e6d57c5130af959bd2860df32775e7.zip |
Video model refractoring -> use mongoose api
Diffstat (limited to 'server/middlewares')
-rw-r--r-- | server/middlewares/reqValidators/remote.js | 2 | ||||
-rw-r--r-- | server/middlewares/reqValidators/videos.js | 20 |
2 files changed, 11 insertions, 11 deletions
diff --git a/server/middlewares/reqValidators/remote.js b/server/middlewares/reqValidators/remote.js index a23673d89..dd8ee5f6e 100644 --- a/server/middlewares/reqValidators/remote.js +++ b/server/middlewares/reqValidators/remote.js | |||
@@ -22,7 +22,7 @@ function remoteVideos (req, res, next) { | |||
22 | req.checkBody('data').isArray() | 22 | req.checkBody('data').isArray() |
23 | req.checkBody('data').isEachRemoteVideosValid() | 23 | req.checkBody('data').isEachRemoteVideosValid() |
24 | 24 | ||
25 | logger.debug('Checking remoteVideosAdd parameters', { parameters: req.body }) | 25 | logger.debug('Checking remoteVideos parameters', { parameters: req.body }) |
26 | 26 | ||
27 | checkErrors(req, res, next) | 27 | checkErrors(req, res, next) |
28 | } | 28 | } |
diff --git a/server/middlewares/reqValidators/videos.js b/server/middlewares/reqValidators/videos.js index f31fd93a2..452fbc859 100644 --- a/server/middlewares/reqValidators/videos.js +++ b/server/middlewares/reqValidators/videos.js | |||
@@ -1,11 +1,13 @@ | |||
1 | 'use strict' | 1 | 'use strict' |
2 | 2 | ||
3 | const mongoose = require('mongoose') | ||
4 | |||
3 | const checkErrors = require('./utils').checkErrors | 5 | const checkErrors = require('./utils').checkErrors |
4 | const constants = require('../../initializers/constants') | 6 | const constants = require('../../initializers/constants') |
5 | const customValidators = require('../../helpers/customValidators') | 7 | const customValidators = require('../../helpers/customValidators') |
6 | const logger = require('../../helpers/logger') | 8 | const logger = require('../../helpers/logger') |
7 | const videos = require('../../lib/videos') | 9 | |
8 | const Videos = require('../../models/videos') | 10 | const Video = mongoose.model('Video') |
9 | 11 | ||
10 | const reqValidatorsVideos = { | 12 | const reqValidatorsVideos = { |
11 | videosAdd: videosAdd, | 13 | videosAdd: videosAdd, |
@@ -26,7 +28,7 @@ function videosAdd (req, res, next) { | |||
26 | checkErrors(req, res, function () { | 28 | checkErrors(req, res, function () { |
27 | const videoFile = req.files.videofile[0] | 29 | const videoFile = req.files.videofile[0] |
28 | 30 | ||
29 | videos.getVideoDuration(videoFile.path, function (err, duration) { | 31 | Video.getDurationFromFile(videoFile.path, function (err, duration) { |
30 | if (err) { | 32 | if (err) { |
31 | return res.status(400).send('Cannot retrieve metadata of the file.') | 33 | return res.status(400).send('Cannot retrieve metadata of the file.') |
32 | } | 34 | } |
@@ -47,14 +49,13 @@ function videosGet (req, res, next) { | |||
47 | logger.debug('Checking videosGet parameters', { parameters: req.params }) | 49 | logger.debug('Checking videosGet parameters', { parameters: req.params }) |
48 | 50 | ||
49 | checkErrors(req, res, function () { | 51 | checkErrors(req, res, function () { |
50 | Videos.get(req.params.id, function (err, video) { | 52 | Video.load(req.params.id, function (err, video) { |
51 | if (err) { | 53 | if (err) { |
52 | logger.error('Error in videosGet request validator.', { error: err }) | 54 | logger.error('Error in videosGet request validator.', { error: err }) |
53 | return res.sendStatus(500) | 55 | return res.sendStatus(500) |
54 | } | 56 | } |
55 | 57 | ||
56 | const state = videos.getVideoState(video) | 58 | if (!video) return res.status(404).send('Video not found') |
57 | if (state.exist === false) return res.status(404).send('Video not found') | ||
58 | 59 | ||
59 | next() | 60 | next() |
60 | }) | 61 | }) |
@@ -67,15 +68,14 @@ function videosRemove (req, res, next) { | |||
67 | logger.debug('Checking videosRemove parameters', { parameters: req.params }) | 68 | logger.debug('Checking videosRemove parameters', { parameters: req.params }) |
68 | 69 | ||
69 | checkErrors(req, res, function () { | 70 | checkErrors(req, res, function () { |
70 | Videos.get(req.params.id, function (err, video) { | 71 | Video.load(req.params.id, function (err, video) { |
71 | if (err) { | 72 | if (err) { |
72 | logger.error('Error in videosRemove request validator.', { error: err }) | 73 | logger.error('Error in videosRemove request validator.', { error: err }) |
73 | return res.sendStatus(500) | 74 | return res.sendStatus(500) |
74 | } | 75 | } |
75 | 76 | ||
76 | const state = videos.getVideoState(video) | 77 | if (!video) return res.status(404).send('Video not found') |
77 | if (state.exist === false) return res.status(404).send('Video not found') | 78 | else if (video.isOwned() === false) return res.status(403).send('Cannot remove video of another pod') |
78 | else if (state.owned === false) return res.status(403).send('Cannot remove video of another pod') | ||
79 | 79 | ||
80 | next() | 80 | next() |
81 | }) | 81 | }) |