mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-06 03:50:26 +02:00
Video lib/model/reqvalidator refractoring
This commit is contained in:
parent
86e054b20f
commit
5101105ef9
3 changed files with 23 additions and 41 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
var checkErrors = require('./utils').checkErrors
|
||||
var logger = require('../../helpers/logger')
|
||||
var videos = require('../../lib/videos')
|
||||
var Videos = require('../../models/videos')
|
||||
|
||||
var reqValidatorsVideos = {
|
||||
|
@ -28,15 +29,17 @@ function videosGet (req, res, next) {
|
|||
logger.debug('Checking videosGet parameters', { parameters: req.params })
|
||||
|
||||
checkErrors(req, res, function () {
|
||||
Videos.getVideoState(req.params.id, function (err, state) {
|
||||
Videos.get(req.params.id, function (err, video) {
|
||||
if (err) {
|
||||
logger.error('Error in videosGet request validator.', { error: err })
|
||||
res.sendStatus(500)
|
||||
}
|
||||
|
||||
if (state.exist === false) return res.status(404).send('Video not found')
|
||||
videos.getVideoState(video, function (state) {
|
||||
if (state.exist === false) return res.status(404).send('Video not found')
|
||||
|
||||
next()
|
||||
next()
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
@ -47,16 +50,18 @@ function videosRemove (req, res, next) {
|
|||
logger.debug('Checking videosRemove parameters', { parameters: req.params })
|
||||
|
||||
checkErrors(req, res, function () {
|
||||
Videos.getVideoState(req.params.id, function (err, state) {
|
||||
Videos.get(req.params.id, function (err, video) {
|
||||
if (err) {
|
||||
logger.error('Error in videosRemove request validator.', { error: err })
|
||||
res.sendStatus(500)
|
||||
}
|
||||
|
||||
if (state.exist === false) return res.status(404).send('Video not found')
|
||||
else if (state.owned === false) return res.status(403).send('Cannot remove video of another pod')
|
||||
videos.getVideoState(video, function (state) {
|
||||
if (state.exist === false) return res.status(404).send('Video not found')
|
||||
else if (state.owned === false) return res.status(403).send('Cannot remove video of another pod')
|
||||
|
||||
next()
|
||||
next()
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue