aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/pods.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/pods.js')
-rw-r--r--server/controllers/api/pods.js34
1 files changed, 11 insertions, 23 deletions
diff --git a/server/controllers/api/pods.js b/server/controllers/api/pods.js
index 7857fcee0..38702face 100644
--- a/server/controllers/api/pods.js
+++ b/server/controllers/api/pods.js
@@ -1,10 +1,11 @@
1'use strict' 1'use strict'
2 2
3const express = require('express') 3const express = require('express')
4const mongoose = require('mongoose')
5const waterfall = require('async/waterfall') 4const waterfall = require('async/waterfall')
6 5
6const db = require('../../initializers/database')
7const logger = require('../../helpers/logger') 7const logger = require('../../helpers/logger')
8const utils = require('../../helpers/utils')
8const friends = require('../../lib/friends') 9const friends = require('../../lib/friends')
9const middlewares = require('../../middlewares') 10const middlewares = require('../../middlewares')
10const admin = middlewares.admin 11const admin = middlewares.admin
@@ -15,7 +16,6 @@ const validators = middlewares.validators.pods
15const signatureValidator = middlewares.validators.remote.signature 16const signatureValidator = middlewares.validators.remote.signature
16 17
17const router = express.Router() 18const router = express.Router()
18const Pod = mongoose.model('Pod')
19 19
20router.get('/', listPods) 20router.get('/', listPods)
21router.post('/', 21router.post('/',
@@ -37,7 +37,7 @@ router.get('/quitfriends',
37) 37)
38// Post because this is a secured request 38// Post because this is a secured request
39router.post('/remove', 39router.post('/remove',
40 signatureValidator, 40 signatureValidator.signature,
41 checkSignature, 41 checkSignature,
42 removePods 42 removePods
43) 43)
@@ -53,15 +53,15 @@ function addPods (req, res, next) {
53 53
54 waterfall([ 54 waterfall([
55 function addPod (callback) { 55 function addPod (callback) {
56 const pod = new Pod(informations) 56 const pod = db.Pod.build(informations)
57 pod.save(function (err, podCreated) { 57 pod.save().asCallback(function (err, podCreated) {
58 // Be sure about the number of parameters for the callback 58 // Be sure about the number of parameters for the callback
59 return callback(err, podCreated) 59 return callback(err, podCreated)
60 }) 60 })
61 }, 61 },
62 62
63 function sendMyVideos (podCreated, callback) { 63 function sendMyVideos (podCreated, callback) {
64 friends.sendOwnedVideosToPod(podCreated._id) 64 friends.sendOwnedVideosToPod(podCreated.id)
65 65
66 callback(null) 66 callback(null)
67 }, 67 },
@@ -84,10 +84,10 @@ function addPods (req, res, next) {
84} 84}
85 85
86function listPods (req, res, next) { 86function listPods (req, res, next) {
87 Pod.list(function (err, podsList) { 87 db.Pod.list(function (err, podsList) {
88 if (err) return next(err) 88 if (err) return next(err)
89 89
90 res.json(getFormatedPods(podsList)) 90 res.json(utils.getFormatedObjects(podsList, podsList.length))
91 }) 91 })
92} 92}
93 93
@@ -111,11 +111,11 @@ function removePods (req, res, next) {
111 111
112 waterfall([ 112 waterfall([
113 function loadPod (callback) { 113 function loadPod (callback) {
114 Pod.loadByHost(host, callback) 114 db.Pod.loadByHost(host, callback)
115 }, 115 },
116 116
117 function removePod (pod, callback) { 117 function deletePod (pod, callback) {
118 pod.remove(callback) 118 pod.destroy().asCallback(callback)
119 } 119 }
120 ], function (err) { 120 ], function (err) {
121 if (err) return next(err) 121 if (err) return next(err)
@@ -131,15 +131,3 @@ function quitFriends (req, res, next) {
131 res.type('json').status(204).end() 131 res.type('json').status(204).end()
132 }) 132 })
133} 133}
134
135// ---------------------------------------------------------------------------
136
137function getFormatedPods (pods) {
138 const formatedPods = []
139
140 pods.forEach(function (pod) {
141 formatedPods.push(pod.toFormatedJSON())
142 })
143
144 return formatedPods
145}