aboutsummaryrefslogtreecommitdiffhomepage
path: root/routes/api/v1/pods.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-01-23 18:31:58 +0100
committerChocobozzz <florian.bigard@gmail.com>2016-01-23 18:31:58 +0100
commit45239549bf2659998dcf9196d86974b0b625912e (patch)
tree823d324db097400a7b5ae59a03deff54c5fd86ef /routes/api/v1/pods.js
parent2cc8ebf134b66047cd639ee7324e1ecfd5c5fd18 (diff)
downloadPeerTube-45239549bf2659998dcf9196d86974b0b625912e.tar.gz
PeerTube-45239549bf2659998dcf9196d86974b0b625912e.tar.zst
PeerTube-45239549bf2659998dcf9196d86974b0b625912e.zip
Finalise the join in a network and add the ability to quit it
Diffstat (limited to 'routes/api/v1/pods.js')
-rw-r--r--routes/api/v1/pods.js31
1 files changed, 30 insertions, 1 deletions
diff --git a/routes/api/v1/pods.js b/routes/api/v1/pods.js
index 2bb8f89ab..2430b0d7e 100644
--- a/routes/api/v1/pods.js
+++ b/routes/api/v1/pods.js
@@ -6,6 +6,7 @@
6 var middleware = require('../../../middlewares') 6 var middleware = require('../../../middlewares')
7 var miscMiddleware = middleware.misc 7 var miscMiddleware = middleware.misc
8 var reqValidator = middleware.reqValidators.pods 8 var reqValidator = middleware.reqValidators.pods
9 var secureRequest = middleware.reqValidators.remote.secureRequest
9 var pods = require('../../../src/pods') 10 var pods = require('../../../src/pods')
10 11
11 function listPods (req, res, next) { 12 function listPods (req, res, next) {
@@ -24,8 +25,33 @@
24 }) 25 })
25 } 26 }
26 27
28 function removePods (req, res, next) {
29 pods.remove(req.body.signature.url, function (err) {
30 if (err) return next(err)
31
32 res.sendStatus(204)
33 })
34 }
35
27 function makeFriends (req, res, next) { 36 function makeFriends (req, res, next) {
28 pods.makeFriends(function (err) { 37 pods.hasFriends(function (err, has_friends) {
38 if (err) return next(err)
39
40 if (has_friends === true) {
41 // We need to quit our friends before make new ones
42 res.sendStatus(409)
43 } else {
44 pods.makeFriends(function (err) {
45 if (err) return next(err)
46
47 res.sendStatus(204)
48 })
49 }
50 })
51 }
52
53 function quitFriends (req, res, next) {
54 pods.quitFriends(function (err) {
29 if (err) return next(err) 55 if (err) return next(err)
30 56
31 res.sendStatus(204) 57 res.sendStatus(204)
@@ -34,7 +60,10 @@
34 60
35 router.get('/', miscMiddleware.cache(false), listPods) 61 router.get('/', miscMiddleware.cache(false), listPods)
36 router.get('/makefriends', miscMiddleware.cache(false), makeFriends) 62 router.get('/makefriends', miscMiddleware.cache(false), makeFriends)
63 router.get('/quitfriends', miscMiddleware.cache(false), quitFriends)
37 router.post('/', reqValidator.podsAdd, miscMiddleware.cache(false), addPods) 64 router.post('/', reqValidator.podsAdd, miscMiddleware.cache(false), addPods)
65 // Post because this is a secured request
66 router.post('/remove', secureRequest, miscMiddleware.decryptBody, removePods)
38 67
39 module.exports = router 68 module.exports = router
40})() 69})()