aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-01-27 11:55:31 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-01-27 11:55:31 +0100
commitb09ce6455f8e2bf9dd741532e6ad09309880ff74 (patch)
tree7d2ec942e50b8f3347ed4287e07e2bc88619e585 /server/middlewares
parent0d4fb7e6d482635cd725cd2f09cf981f82cbd92c (diff)
downloadPeerTube-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')
-rw-r--r--server/middlewares/pods.js4
-rw-r--r--server/middlewares/validators/pods.js26
2 files changed, 23 insertions, 7 deletions
diff --git a/server/middlewares/pods.js b/server/middlewares/pods.js
index e38fb341d..2647f9ff0 100644
--- a/server/middlewares/pods.js
+++ b/server/middlewares/pods.js
@@ -8,6 +8,8 @@ const podsMiddleware = {
8} 8}
9 9
10function setBodyHostsPort (req, res, next) { 10function setBodyHostsPort (req, res, next) {
11 if (!req.body.hosts) return next()
12
11 for (let i = 0; i < req.body.hosts.length; i++) { 13 for (let i = 0; i < req.body.hosts.length; i++) {
12 const hostWithPort = getHostWithPort(req.body.hosts[i]) 14 const hostWithPort = getHostWithPort(req.body.hosts[i])
13 15
@@ -23,6 +25,8 @@ function setBodyHostsPort (req, res, next) {
23} 25}
24 26
25function setBodyHostPort (req, res, next) { 27function setBodyHostPort (req, res, next) {
28 if (!req.body.host) return next()
29
26 const hostWithPort = getHostWithPort(req.body.host) 30 const hostWithPort = getHostWithPort(req.body.host)
27 31
28 // Problem with the url parsing? 32 // Problem with the url parsing?
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
3const checkErrors = require('./utils').checkErrors 3const checkErrors = require('./utils').checkErrors
4const constants = require('../../initializers/constants') 4const constants = require('../../initializers/constants')
5const db = require('../../initializers/database')
5const friends = require('../../lib/friends') 6const friends = require('../../lib/friends')
6const logger = require('../../helpers/logger') 7const logger = require('../../helpers/logger')
7const utils = require('../../helpers/utils') 8const 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
41function podsAdd (req, res, next) { 42function 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// ---------------------------------------------------------------------------