aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/v1/pods.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-06-18 16:13:54 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-06-18 16:13:54 +0200
commit528a9efa8272532bbd0dafc35c3e05e57c50f61e (patch)
tree62d4417df4ab9b2e53c44dc7271be81b88e4e0e5 /server/controllers/api/v1/pods.js
parentb2e4c0ba1a33b8a50491a1f8d111468a7da5640f (diff)
downloadPeerTube-528a9efa8272532bbd0dafc35c3e05e57c50f61e.tar.gz
PeerTube-528a9efa8272532bbd0dafc35c3e05e57c50f61e.tar.zst
PeerTube-528a9efa8272532bbd0dafc35c3e05e57c50f61e.zip
Try to make a better communication (between pods) module
Diffstat (limited to 'server/controllers/api/v1/pods.js')
-rw-r--r--server/controllers/api/v1/pods.js43
1 files changed, 13 insertions, 30 deletions
diff --git a/server/controllers/api/v1/pods.js b/server/controllers/api/v1/pods.js
index ecaeba666..881b2090d 100644
--- a/server/controllers/api/v1/pods.js
+++ b/server/controllers/api/v1/pods.js
@@ -9,19 +9,18 @@ const middlewares = require('../../../middlewares')
9const Pods = require('../../../models/pods') 9const Pods = require('../../../models/pods')
10const oAuth2 = middlewares.oauth2 10const oAuth2 = middlewares.oauth2
11const reqValidator = middlewares.reqValidators.pods 11const reqValidator = middlewares.reqValidators.pods
12const secureMiddleware = middlewares.secure 12const signatureValidator = middlewares.reqValidators.remote.signature
13const secureRequest = middlewares.reqValidators.remote.secureRequest
14const videos = require('../../../lib/videos') 13const videos = require('../../../lib/videos')
15const Videos = require('../../../models/videos') 14const Videos = require('../../../models/videos')
16 15
17const router = express.Router() 16const router = express.Router()
18 17
19router.get('/', listPods) 18router.get('/', listPodsUrl)
20router.post('/', reqValidator.podsAdd, addPods) 19router.post('/', reqValidator.podsAdd, addPods)
21router.get('/makefriends', oAuth2.authenticate, reqValidator.makeFriends, makeFriends) 20router.get('/makefriends', oAuth2.authenticate, reqValidator.makeFriends, makeFriends)
22router.get('/quitfriends', oAuth2.authenticate, quitFriends) 21router.get('/quitfriends', oAuth2.authenticate, quitFriends)
23// Post because this is a secured request 22// Post because this is a secured request
24router.post('/remove', secureRequest, secureMiddleware.decryptBody, removePods) 23router.post('/remove', signatureValidator, removePods)
25 24
26// --------------------------------------------------------------------------- 25// ---------------------------------------------------------------------------
27 26
@@ -30,22 +29,17 @@ module.exports = router
30// --------------------------------------------------------------------------- 29// ---------------------------------------------------------------------------
31 30
32function addPods (req, res, next) { 31function addPods (req, res, next) {
33 const informations = req.body.data 32 const informations = req.body
34 33
35 async.waterfall([ 34 async.waterfall([
36 function addPod (callback) { 35 function addPod (callback) {
37 Pods.add(informations, function (err) { 36 Pods.add(informations, callback)
38 return callback(err)
39 })
40 }, 37 },
41 38
42 function createVideosOfThisPod (callback) { 39 function sendMyVideos (podCreated, callback) {
43 // Create the remote videos from the new pod 40 friends.sendOwnedVideosToPod(podCreated._id)
44 videos.createRemoteVideos(informations.videos, function (err) {
45 if (err) logger.error('Cannot create remote videos.', { error: err })
46 41
47 return callback(err) 42 callback(null)
48 })
49 }, 43 },
50 44
51 function fetchMyCertificate (callback) { 45 function fetchMyCertificate (callback) {
@@ -57,30 +51,19 @@ function addPods (req, res, next) {
57 51
58 return callback(null, cert) 52 return callback(null, cert)
59 }) 53 })
60 },
61
62 function getListOfMyVideos (cert, callback) {
63 Videos.listOwned(function (err, videosList) {
64 if (err) {
65 logger.error('Cannot get the list of owned videos.')
66 return callback(err)
67 }
68
69 return callback(null, cert, videosList)
70 })
71 } 54 }
72 ], function (err, cert, videosList) { 55 ], function (err, cert) {
73 if (err) return next(err) 56 if (err) return next(err)
74 57
75 return res.json({ cert: cert, videos: videosList }) 58 return res.json({ cert: cert })
76 }) 59 })
77} 60}
78 61
79function listPods (req, res, next) { 62function listPodsUrl (req, res, next) {
80 Pods.list(function (err, podsList) { 63 Pods.listAllUrls(function (err, podsUrlList) {
81 if (err) return next(err) 64 if (err) return next(err)
82 65
83 res.json(podsList) 66 res.json(podsUrlList)
84 }) 67 })
85} 68}
86 69