aboutsummaryrefslogtreecommitdiffhomepage
path: root/routes/api
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
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')
-rw-r--r--routes/api/v1/pods.js31
-rw-r--r--routes/api/v1/remoteVideos.js2
2 files changed, 31 insertions, 2 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})()
diff --git a/routes/api/v1/remoteVideos.js b/routes/api/v1/remoteVideos.js
index a104113b2..6ba6ce17b 100644
--- a/routes/api/v1/remoteVideos.js
+++ b/routes/api/v1/remoteVideos.js
@@ -22,7 +22,7 @@
22 videos.removeRemotes(req.body.signature.url, pluck(req.body.data, 'magnetUri'), function (err) { 22 videos.removeRemotes(req.body.signature.url, pluck(req.body.data, 'magnetUri'), function (err) {
23 if (err) return next(err) 23 if (err) return next(err)
24 24
25 res.status(204) 25 res.sendStatus(204)
26 }) 26 })
27 } 27 }
28 28