aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/v1/pods.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/v1/pods.js')
-rw-r--r--server/controllers/api/v1/pods.js62
1 files changed, 51 insertions, 11 deletions
diff --git a/server/controllers/api/v1/pods.js b/server/controllers/api/v1/pods.js
index 2bc761fef..8ffade578 100644
--- a/server/controllers/api/v1/pods.js
+++ b/server/controllers/api/v1/pods.js
@@ -8,7 +8,10 @@ const waterfall = require('async/waterfall')
8const logger = require('../../../helpers/logger') 8const logger = require('../../../helpers/logger')
9const friends = require('../../../lib/friends') 9const friends = require('../../../lib/friends')
10const middlewares = require('../../../middlewares') 10const middlewares = require('../../../middlewares')
11const admin = middlewares.admin
11const oAuth = middlewares.oauth 12const oAuth = middlewares.oauth
13const podsMiddleware = middlewares.pods
14const checkSignature = middlewares.secure.checkSignature
12const validators = middlewares.validators.pods 15const validators = middlewares.validators.pods
13const signatureValidator = middlewares.validators.remote.signature 16const signatureValidator = middlewares.validators.remote.signature
14 17
@@ -16,12 +19,30 @@ const router = express.Router()
16const Pod = mongoose.model('Pod') 19const Pod = mongoose.model('Pod')
17const Video = mongoose.model('Video') 20const Video = mongoose.model('Video')
18 21
19router.get('/', listPodsUrl) 22router.get('/', listPods)
20router.post('/', validators.podsAdd, addPods) 23router.post('/',
21router.get('/makefriends', oAuth.authenticate, validators.makeFriends, makeFriends) 24 validators.podsAdd,
22router.get('/quitfriends', oAuth.authenticate, quitFriends) 25 podsMiddleware.setBodyUrlPort,
26 addPods
27)
28router.post('/makefriends',
29 oAuth.authenticate,
30 admin.ensureIsAdmin,
31 validators.makeFriends,
32 podsMiddleware.setBodyUrlsPort,
33 makeFriends
34)
35router.get('/quitfriends',
36 oAuth.authenticate,
37 admin.ensureIsAdmin,
38 quitFriends
39)
23// Post because this is a secured request 40// Post because this is a secured request
24router.post('/remove', signatureValidator, removePods) 41router.post('/remove',
42 signatureValidator,
43 checkSignature,
44 removePods
45)
25 46
26// --------------------------------------------------------------------------- 47// ---------------------------------------------------------------------------
27 48
@@ -64,20 +85,27 @@ function addPods (req, res, next) {
64 }) 85 })
65} 86}
66 87
67function listPodsUrl (req, res, next) { 88function listPods (req, res, next) {
68 Pod.listOnlyUrls(function (err, podsUrlList) { 89 Pod.list(function (err, podsUrlList) {
69 if (err) return next(err) 90 if (err) return next(err)
70 91
71 res.json(podsUrlList) 92 res.json(getFormatedPods(podsUrlList))
72 }) 93 })
73} 94}
74 95
75function makeFriends (req, res, next) { 96function makeFriends (req, res, next) {
76 friends.makeFriends(function (err) { 97 const urls = req.body.urls
77 if (err) return next(err)
78 98
79 res.type('json').status(204).end() 99 friends.makeFriends(urls, function (err) {
100 if (err) {
101 logger.error('Could not make friends.', { error: err })
102 return
103 }
104
105 logger.info('Made friends!')
80 }) 106 })
107
108 res.type('json').status(204).end()
81} 109}
82 110
83function removePods (req, res, next) { 111function removePods (req, res, next) {
@@ -125,3 +153,15 @@ function quitFriends (req, res, next) {
125 res.type('json').status(204).end() 153 res.type('json').status(204).end()
126 }) 154 })
127} 155}
156
157// ---------------------------------------------------------------------------
158
159function getFormatedPods (pods) {
160 const formatedPods = []
161
162 pods.forEach(function (pod) {
163 formatedPods.push(pod.toFormatedJSON())
164 })
165
166 return formatedPods
167}