diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-06-18 16:13:54 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-06-18 16:13:54 +0200 |
commit | 528a9efa8272532bbd0dafc35c3e05e57c50f61e (patch) | |
tree | 62d4417df4ab9b2e53c44dc7271be81b88e4e0e5 /server/controllers/api/v1/pods.js | |
parent | b2e4c0ba1a33b8a50491a1f8d111468a7da5640f (diff) | |
download | PeerTube-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.js | 43 |
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') | |||
9 | const Pods = require('../../../models/pods') | 9 | const Pods = require('../../../models/pods') |
10 | const oAuth2 = middlewares.oauth2 | 10 | const oAuth2 = middlewares.oauth2 |
11 | const reqValidator = middlewares.reqValidators.pods | 11 | const reqValidator = middlewares.reqValidators.pods |
12 | const secureMiddleware = middlewares.secure | 12 | const signatureValidator = middlewares.reqValidators.remote.signature |
13 | const secureRequest = middlewares.reqValidators.remote.secureRequest | ||
14 | const videos = require('../../../lib/videos') | 13 | const videos = require('../../../lib/videos') |
15 | const Videos = require('../../../models/videos') | 14 | const Videos = require('../../../models/videos') |
16 | 15 | ||
17 | const router = express.Router() | 16 | const router = express.Router() |
18 | 17 | ||
19 | router.get('/', listPods) | 18 | router.get('/', listPodsUrl) |
20 | router.post('/', reqValidator.podsAdd, addPods) | 19 | router.post('/', reqValidator.podsAdd, addPods) |
21 | router.get('/makefriends', oAuth2.authenticate, reqValidator.makeFriends, makeFriends) | 20 | router.get('/makefriends', oAuth2.authenticate, reqValidator.makeFriends, makeFriends) |
22 | router.get('/quitfriends', oAuth2.authenticate, quitFriends) | 21 | router.get('/quitfriends', oAuth2.authenticate, quitFriends) |
23 | // Post because this is a secured request | 22 | // Post because this is a secured request |
24 | router.post('/remove', secureRequest, secureMiddleware.decryptBody, removePods) | 23 | router.post('/remove', signatureValidator, removePods) |
25 | 24 | ||
26 | // --------------------------------------------------------------------------- | 25 | // --------------------------------------------------------------------------- |
27 | 26 | ||
@@ -30,22 +29,17 @@ module.exports = router | |||
30 | // --------------------------------------------------------------------------- | 29 | // --------------------------------------------------------------------------- |
31 | 30 | ||
32 | function addPods (req, res, next) { | 31 | function 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 | ||
79 | function listPods (req, res, next) { | 62 | function 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 | ||