diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-06-30 22:39:08 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-06-30 22:39:08 +0200 |
commit | a3ee6fa22dee4b68fcde9cd23708b471db446e11 (patch) | |
tree | b05543f6d858c52dd4757123bc605277ede96983 /server/controllers/api/v1/pods.js | |
parent | d14b3e37a2c0d647b59259bf2ca059b5817f144c (diff) | |
download | PeerTube-a3ee6fa22dee4b68fcde9cd23708b471db446e11.tar.gz PeerTube-a3ee6fa22dee4b68fcde9cd23708b471db446e11.tar.zst PeerTube-a3ee6fa22dee4b68fcde9cd23708b471db446e11.zip |
Pod model refractoring -> use mongoose api
Diffstat (limited to 'server/controllers/api/v1/pods.js')
-rw-r--r-- | server/controllers/api/v1/pods.js | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/server/controllers/api/v1/pods.js b/server/controllers/api/v1/pods.js index 9dd9197b3..feb6bd958 100644 --- a/server/controllers/api/v1/pods.js +++ b/server/controllers/api/v1/pods.js | |||
@@ -7,12 +7,12 @@ const mongoose = require('mongoose') | |||
7 | const logger = require('../../../helpers/logger') | 7 | const logger = require('../../../helpers/logger') |
8 | const friends = require('../../../lib/friends') | 8 | const friends = require('../../../lib/friends') |
9 | const middlewares = require('../../../middlewares') | 9 | const middlewares = require('../../../middlewares') |
10 | const Pods = require('../../../models/pods') | ||
11 | const oAuth2 = middlewares.oauth2 | 10 | const oAuth2 = middlewares.oauth2 |
12 | const reqValidator = middlewares.reqValidators.pods | 11 | const reqValidator = middlewares.reqValidators.pods |
13 | const signatureValidator = middlewares.reqValidators.remote.signature | 12 | const signatureValidator = middlewares.reqValidators.remote.signature |
14 | 13 | ||
15 | const router = express.Router() | 14 | const router = express.Router() |
15 | const Pod = mongoose.model('Pod') | ||
16 | const Video = mongoose.model('Video') | 16 | const Video = mongoose.model('Video') |
17 | 17 | ||
18 | router.get('/', listPodsUrl) | 18 | router.get('/', listPodsUrl) |
@@ -33,7 +33,11 @@ function addPods (req, res, next) { | |||
33 | 33 | ||
34 | async.waterfall([ | 34 | async.waterfall([ |
35 | function addPod (callback) { | 35 | function addPod (callback) { |
36 | Pods.add(informations, callback) | 36 | const pod = new Pod(informations) |
37 | pod.save(function (err, podCreated) { | ||
38 | // Be sure about the number of parameters for the callback | ||
39 | return callback(err, podCreated) | ||
40 | }) | ||
37 | }, | 41 | }, |
38 | 42 | ||
39 | function sendMyVideos (podCreated, callback) { | 43 | function sendMyVideos (podCreated, callback) { |
@@ -60,7 +64,7 @@ function addPods (req, res, next) { | |||
60 | } | 64 | } |
61 | 65 | ||
62 | function listPodsUrl (req, res, next) { | 66 | function listPodsUrl (req, res, next) { |
63 | Pods.listAllUrls(function (err, podsUrlList) { | 67 | Pod.listOnlyUrls(function (err, podsUrlList) { |
64 | if (err) return next(err) | 68 | if (err) return next(err) |
65 | 69 | ||
66 | res.json(podsUrlList) | 70 | res.json(podsUrlList) |
@@ -79,8 +83,13 @@ function removePods (req, res, next) { | |||
79 | const url = req.body.signature.url | 83 | const url = req.body.signature.url |
80 | 84 | ||
81 | async.waterfall([ | 85 | async.waterfall([ |
82 | function (callback) { | 86 | function loadPod (callback) { |
83 | Pods.remove(url, function (err) { | 87 | Pod.loadByUrl(url, callback) |
88 | }, | ||
89 | |||
90 | function removePod (pod, callback) { | ||
91 | pod.remove(function (err) { | ||
92 | // Be sure we only return one argument in the callback | ||
84 | return callback(err) | 93 | return callback(err) |
85 | }) | 94 | }) |
86 | }, | 95 | }, |