diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-01-12 15:20:03 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-01-12 15:20:03 +0100 |
commit | 99fe265a5fc077cb66c322e7f3d191ff7110aea0 (patch) | |
tree | c9e04ccfcc5496d2300d7c26db5833e494b4cdad /server/controllers/api/pods.js | |
parent | fcc5f77b95d330bfcb439c172b7fcc58f3162e4d (diff) | |
parent | 91cc839af88730ba55f84997c56b85ea100070a7 (diff) | |
download | PeerTube-99fe265a5fc077cb66c322e7f3d191ff7110aea0.tar.gz PeerTube-99fe265a5fc077cb66c322e7f3d191ff7110aea0.tar.zst PeerTube-99fe265a5fc077cb66c322e7f3d191ff7110aea0.zip |
Merge branch 'postgresql'
Diffstat (limited to 'server/controllers/api/pods.js')
-rw-r--r-- | server/controllers/api/pods.js | 34 |
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 | ||
3 | const express = require('express') | 3 | const express = require('express') |
4 | const mongoose = require('mongoose') | ||
5 | const waterfall = require('async/waterfall') | 4 | const waterfall = require('async/waterfall') |
6 | 5 | ||
6 | const db = require('../../initializers/database') | ||
7 | const logger = require('../../helpers/logger') | 7 | const logger = require('../../helpers/logger') |
8 | const utils = require('../../helpers/utils') | ||
8 | const friends = require('../../lib/friends') | 9 | const friends = require('../../lib/friends') |
9 | const middlewares = require('../../middlewares') | 10 | const middlewares = require('../../middlewares') |
10 | const admin = middlewares.admin | 11 | const admin = middlewares.admin |
@@ -15,7 +16,6 @@ const validators = middlewares.validators.pods | |||
15 | const signatureValidator = middlewares.validators.remote.signature | 16 | const signatureValidator = middlewares.validators.remote.signature |
16 | 17 | ||
17 | const router = express.Router() | 18 | const router = express.Router() |
18 | const Pod = mongoose.model('Pod') | ||
19 | 19 | ||
20 | router.get('/', listPods) | 20 | router.get('/', listPods) |
21 | router.post('/', | 21 | router.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 |
39 | router.post('/remove', | 39 | router.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 | ||
86 | function listPods (req, res, next) { | 86 | function 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 | |||
137 | function getFormatedPods (pods) { | ||
138 | const formatedPods = [] | ||
139 | |||
140 | pods.forEach(function (pod) { | ||
141 | formatedPods.push(pod.toFormatedJSON()) | ||
142 | }) | ||
143 | |||
144 | return formatedPods | ||
145 | } | ||