From b9a3e09ad5a7673f64556d1dba122ed4c4fac980 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 7 Mar 2016 11:33:59 +0100 Subject: Prepare folders structure for angular app --- middlewares/reqValidators/index.js | 15 -------- middlewares/reqValidators/pods.js | 39 ------------------- middlewares/reqValidators/remote.js | 43 --------------------- middlewares/reqValidators/utils.js | 25 ------------- middlewares/reqValidators/videos.js | 74 ------------------------------------- 5 files changed, 196 deletions(-) delete mode 100644 middlewares/reqValidators/index.js delete mode 100644 middlewares/reqValidators/pods.js delete mode 100644 middlewares/reqValidators/remote.js delete mode 100644 middlewares/reqValidators/utils.js delete mode 100644 middlewares/reqValidators/videos.js (limited to 'middlewares/reqValidators') diff --git a/middlewares/reqValidators/index.js b/middlewares/reqValidators/index.js deleted file mode 100644 index 345dbd0e2..000000000 --- a/middlewares/reqValidators/index.js +++ /dev/null @@ -1,15 +0,0 @@ -'use strict' - -var podsReqValidators = require('./pods') -var remoteReqValidators = require('./remote') -var videosReqValidators = require('./videos') - -var reqValidators = { - pods: podsReqValidators, - remote: remoteReqValidators, - videos: videosReqValidators -} - -// --------------------------------------------------------------------------- - -module.exports = reqValidators diff --git a/middlewares/reqValidators/pods.js b/middlewares/reqValidators/pods.js deleted file mode 100644 index ef09d51cf..000000000 --- a/middlewares/reqValidators/pods.js +++ /dev/null @@ -1,39 +0,0 @@ -'use strict' - -var checkErrors = require('./utils').checkErrors -var friends = require('../../lib/friends') -var logger = require('../../helpers/logger') - -var reqValidatorsPod = { - makeFriends: makeFriends, - podsAdd: podsAdd -} - -function makeFriends (req, res, next) { - friends.hasFriends(function (err, has_friends) { - if (err) { - logger.error('Cannot know if we have friends.', { error: err }) - res.sendStatus(500) - } - - if (has_friends === true) { - // We need to quit our friends before make new ones - res.sendStatus(409) - } else { - return next() - } - }) -} - -function podsAdd (req, res, next) { - req.checkBody('data.url', 'Should have an url').notEmpty().isURL({ require_protocol: true }) - req.checkBody('data.publicKey', 'Should have a public key').notEmpty() - - logger.debug('Checking podsAdd parameters', { parameters: req.body }) - - checkErrors(req, res, next) -} - -// --------------------------------------------------------------------------- - -module.exports = reqValidatorsPod diff --git a/middlewares/reqValidators/remote.js b/middlewares/reqValidators/remote.js deleted file mode 100644 index 88de16b49..000000000 --- a/middlewares/reqValidators/remote.js +++ /dev/null @@ -1,43 +0,0 @@ -'use strict' - -var checkErrors = require('./utils').checkErrors -var logger = require('../../helpers/logger') - -var reqValidatorsRemote = { - remoteVideosAdd: remoteVideosAdd, - remoteVideosRemove: remoteVideosRemove, - secureRequest: secureRequest -} - -function remoteVideosAdd (req, res, next) { - req.checkBody('data').isArray() - req.checkBody('data').eachIsRemoteVideosAddValid() - - logger.debug('Checking remoteVideosAdd parameters', { parameters: req.body }) - - checkErrors(req, res, next) -} - -function remoteVideosRemove (req, res, next) { - req.checkBody('data').isArray() - req.checkBody('data').eachIsRemoteVideosRemoveValid() - - logger.debug('Checking remoteVideosRemove parameters', { parameters: req.body }) - - checkErrors(req, res, next) -} - -function secureRequest (req, res, next) { - req.checkBody('signature.url', 'Should have a signature url').isURL() - req.checkBody('signature.signature', 'Should have a signature').notEmpty() - req.checkBody('key', 'Should have a key').notEmpty() - req.checkBody('data', 'Should have data').notEmpty() - - logger.debug('Checking secureRequest parameters', { parameters: { data: req.body.data, keyLength: req.body.key.length } }) - - checkErrors(req, res, next) -} - -// --------------------------------------------------------------------------- - -module.exports = reqValidatorsRemote diff --git a/middlewares/reqValidators/utils.js b/middlewares/reqValidators/utils.js deleted file mode 100644 index 46c982571..000000000 --- a/middlewares/reqValidators/utils.js +++ /dev/null @@ -1,25 +0,0 @@ -'use strict' - -var util = require('util') - -var logger = require('../../helpers/logger') - -var reqValidatorsUtils = { - checkErrors: checkErrors -} - -function checkErrors (req, res, next, status_code) { - if (status_code === undefined) status_code = 400 - var errors = req.validationErrors() - - if (errors) { - logger.warn('Incorrect request parameters', { path: req.originalUrl, err: errors }) - return res.status(status_code).send('There have been validation errors: ' + util.inspect(errors)) - } - - return next() -} - -// --------------------------------------------------------------------------- - -module.exports = reqValidatorsUtils diff --git a/middlewares/reqValidators/videos.js b/middlewares/reqValidators/videos.js deleted file mode 100644 index 4e5f4391f..000000000 --- a/middlewares/reqValidators/videos.js +++ /dev/null @@ -1,74 +0,0 @@ -'use strict' - -var checkErrors = require('./utils').checkErrors -var logger = require('../../helpers/logger') -var Videos = require('../../models/videos') - -var reqValidatorsVideos = { - videosAdd: videosAdd, - videosGet: videosGet, - videosRemove: videosRemove, - videosSearch: videosSearch -} - -function videosAdd (req, res, next) { - req.checkFiles('input_video[0].originalname', 'Should have an input video').notEmpty() - req.checkFiles('input_video[0].mimetype', 'Should have a correct mime type').matches(/video\/(webm)|(mp4)|(ogg)/i) - req.checkBody('name', 'Should have a name').isLength(1, 50) - req.checkBody('description', 'Should have a description').isLength(1, 250) - - logger.debug('Checking videosAdd parameters', { parameters: req.body, files: req.files }) - - checkErrors(req, res, next) -} - -function videosGet (req, res, next) { - req.checkParams('id', 'Should have a valid id').notEmpty().isMongoId() - - logger.debug('Checking videosGet parameters', { parameters: req.params }) - - checkErrors(req, res, function () { - Videos.getVideoState(req.params.id, function (err, state) { - 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') - - next() - }) - }) -} - -function videosRemove (req, res, next) { - req.checkParams('id', 'Should have a valid id').notEmpty().isMongoId() - - logger.debug('Checking videosRemove parameters', { parameters: req.params }) - - checkErrors(req, res, function () { - Videos.getVideoState(req.params.id, function (err, state) { - 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') - - next() - }) - }) -} - -function videosSearch (req, res, next) { - req.checkParams('name', 'Should have a name').notEmpty() - - logger.debug('Checking videosSearch parameters', { parameters: req.params }) - - checkErrors(req, res, next) -} - -// --------------------------------------------------------------------------- - -module.exports = reqValidatorsVideos -- cgit v1.2.3