diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-01-27 11:55:31 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-01-27 11:55:31 +0100 |
commit | b09ce6455f8e2bf9dd741532e6ad09309880ff74 (patch) | |
tree | 7d2ec942e50b8f3347ed4287e07e2bc88619e585 /server/middlewares/validators | |
parent | 0d4fb7e6d482635cd725cd2f09cf981f82cbd92c (diff) | |
download | PeerTube-b09ce6455f8e2bf9dd741532e6ad09309880ff74.tar.gz PeerTube-b09ce6455f8e2bf9dd741532e6ad09309880ff74.tar.zst PeerTube-b09ce6455f8e2bf9dd741532e6ad09309880ff74.zip |
Server: error if we add a pod that already exists
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r-- | server/middlewares/validators/pods.js | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/server/middlewares/validators/pods.js b/server/middlewares/validators/pods.js index 0723871b2..b9b30e7a1 100644 --- a/server/middlewares/validators/pods.js +++ b/server/middlewares/validators/pods.js | |||
@@ -2,6 +2,7 @@ | |||
2 | 2 | ||
3 | const checkErrors = require('./utils').checkErrors | 3 | const checkErrors = require('./utils').checkErrors |
4 | const constants = require('../../initializers/constants') | 4 | const constants = require('../../initializers/constants') |
5 | const db = require('../../initializers/database') | ||
5 | const friends = require('../../lib/friends') | 6 | const friends = require('../../lib/friends') |
6 | const logger = require('../../helpers/logger') | 7 | const logger = require('../../helpers/logger') |
7 | const utils = require('../../helpers/utils') | 8 | const utils = require('../../helpers/utils') |
@@ -30,23 +31,34 @@ function makeFriends (req, res, next) { | |||
30 | 31 | ||
31 | if (hasFriends === true) { | 32 | if (hasFriends === true) { |
32 | // We need to quit our friends before make new ones | 33 | // We need to quit our friends before make new ones |
33 | res.sendStatus(409) | 34 | return res.sendStatus(409) |
34 | } else { | ||
35 | return next() | ||
36 | } | 35 | } |
36 | |||
37 | return next() | ||
37 | }) | 38 | }) |
38 | }) | 39 | }) |
39 | } | 40 | } |
40 | 41 | ||
41 | function podsAdd (req, res, next) { | 42 | function podsAdd (req, res, next) { |
42 | req.checkBody('host', 'Should have an host').notEmpty().isURL() | 43 | req.checkBody('host', 'Should have an host').isHostValid() |
43 | req.checkBody('publicKey', 'Should have a public key').notEmpty() | 44 | req.checkBody('publicKey', 'Should have a public key').notEmpty() |
45 | logger.debug('Checking podsAdd parameters', { parameters: req.body }) | ||
44 | 46 | ||
45 | // TODO: check we don't have it already | 47 | checkErrors(req, res, function () { |
48 | db.Pod.loadByHost(req.body.host, function (err, pod) { | ||
49 | if (err) { | ||
50 | logger.error('Cannot load pod by host.', { error: err }) | ||
51 | res.sendStatus(500) | ||
52 | } | ||
46 | 53 | ||
47 | logger.debug('Checking podsAdd parameters', { parameters: req.body }) | 54 | // Pod with this host already exists |
55 | if (pod) { | ||
56 | return res.sendStatus(409) | ||
57 | } | ||
48 | 58 | ||
49 | checkErrors(req, res, next) | 59 | return next() |
60 | }) | ||
61 | }) | ||
50 | } | 62 | } |
51 | 63 | ||
52 | // --------------------------------------------------------------------------- | 64 | // --------------------------------------------------------------------------- |