From 818f7987eba27c59793e2103168b26129c9404f2 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 30 Dec 2016 11:51:08 +0100 Subject: Server: optimization for videoGet and videoRemove --- server/middlewares/validators/videos.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'server/middlewares') diff --git a/server/middlewares/validators/videos.js b/server/middlewares/validators/videos.js index 09a188c76..1b6dbccf0 100644 --- a/server/middlewares/validators/videos.js +++ b/server/middlewares/validators/videos.js @@ -71,15 +71,16 @@ function videosRemove (req, res, next) { logger.debug('Checking videosRemove parameters', { parameters: req.params }) checkErrors(req, res, function () { - db.Video.loadAndPopulateAuthor(req.params.id, function (err, video) { - if (err) { - logger.error('Error in videosRemove request validator.', { error: err }) - return res.sendStatus(500) + checkVideoExists(req.params.id, res, function () { + // We need to make additional checks + + if (res.locals.video.isOwned() === false) { + return res.status(403).send('Cannot remove video of another pod') } - if (!video) return res.status(404).send('Video not found') - else if (video.isOwned() === false) return res.status(403).send('Cannot remove video of another pod') - else if (video.Author.name !== res.locals.oauth.token.user.username) return res.status(403).send('Cannot remove video of another user') + if (res.locals.video.authorId !== res.locals.oauth.token.User.id) { + return res.status(403).send('Cannot remove video of another user') + } next() }) -- cgit v1.2.3