diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-03-19 18:56:10 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-03-19 18:56:10 +0100 |
commit | 34831b4843c161248109fb10876c1600578491de (patch) | |
tree | db478bf3819c844a6b54da5b031a27b74f20aeeb /server/controllers/api | |
parent | f148e5edb62c914eff12d7d4a5f879fedcfc64be (diff) | |
download | PeerTube-34831b4843c161248109fb10876c1600578491de.tar.gz PeerTube-34831b4843c161248109fb10876c1600578491de.tar.zst PeerTube-34831b4843c161248109fb10876c1600578491de.zip |
Server: move pod remove to remote path
Diffstat (limited to 'server/controllers/api')
-rw-r--r-- | server/controllers/api/pods.js | 26 | ||||
-rw-r--r-- | server/controllers/api/remote/index.js | 2 | ||||
-rw-r--r-- | server/controllers/api/remote/pods.js | 42 |
3 files changed, 44 insertions, 26 deletions
diff --git a/server/controllers/api/pods.js b/server/controllers/api/pods.js index 1c3eefcc1..ab5763cf6 100644 --- a/server/controllers/api/pods.js +++ b/server/controllers/api/pods.js | |||
@@ -13,9 +13,7 @@ const middlewares = require('../../middlewares') | |||
13 | const admin = middlewares.admin | 13 | const admin = middlewares.admin |
14 | const oAuth = middlewares.oauth | 14 | const oAuth = middlewares.oauth |
15 | const podsMiddleware = middlewares.pods | 15 | const podsMiddleware = middlewares.pods |
16 | const checkSignature = middlewares.secure.checkSignature | ||
17 | const validators = middlewares.validators.pods | 16 | const validators = middlewares.validators.pods |
18 | const signatureValidator = middlewares.validators.remote.signature | ||
19 | 17 | ||
20 | const router = express.Router() | 18 | const router = express.Router() |
21 | 19 | ||
@@ -37,12 +35,6 @@ router.get('/quitfriends', | |||
37 | admin.ensureIsAdmin, | 35 | admin.ensureIsAdmin, |
38 | quitFriends | 36 | quitFriends |
39 | ) | 37 | ) |
40 | // Post because this is a secured request | ||
41 | router.post('/remove', | ||
42 | signatureValidator.signature, | ||
43 | checkSignature, | ||
44 | removePods | ||
45 | ) | ||
46 | 38 | ||
47 | // --------------------------------------------------------------------------- | 39 | // --------------------------------------------------------------------------- |
48 | 40 | ||
@@ -108,24 +100,6 @@ function makeFriends (req, res, next) { | |||
108 | res.type('json').status(204).end() | 100 | res.type('json').status(204).end() |
109 | } | 101 | } |
110 | 102 | ||
111 | function removePods (req, res, next) { | ||
112 | const host = req.body.signature.host | ||
113 | |||
114 | waterfall([ | ||
115 | function loadPod (callback) { | ||
116 | db.Pod.loadByHost(host, callback) | ||
117 | }, | ||
118 | |||
119 | function deletePod (pod, callback) { | ||
120 | pod.destroy().asCallback(callback) | ||
121 | } | ||
122 | ], function (err) { | ||
123 | if (err) return next(err) | ||
124 | |||
125 | return res.type('json').status(204).end() | ||
126 | }) | ||
127 | } | ||
128 | |||
129 | function quitFriends (req, res, next) { | 103 | function quitFriends (req, res, next) { |
130 | friends.quitFriends(function (err) { | 104 | friends.quitFriends(function (err) { |
131 | if (err) return next(err) | 105 | if (err) return next(err) |
diff --git a/server/controllers/api/remote/index.js b/server/controllers/api/remote/index.js index 2947632d5..6106850ab 100644 --- a/server/controllers/api/remote/index.js +++ b/server/controllers/api/remote/index.js | |||
@@ -6,8 +6,10 @@ const utils = require('../../../helpers/utils') | |||
6 | 6 | ||
7 | const router = express.Router() | 7 | const router = express.Router() |
8 | 8 | ||
9 | const podsRemoteController = require('./pods') | ||
9 | const videosRemoteController = require('./videos') | 10 | const videosRemoteController = require('./videos') |
10 | 11 | ||
12 | router.use('/pods', podsRemoteController) | ||
11 | router.use('/videos', videosRemoteController) | 13 | router.use('/videos', videosRemoteController) |
12 | router.use('/*', utils.badRequest) | 14 | router.use('/*', utils.badRequest) |
13 | 15 | ||
diff --git a/server/controllers/api/remote/pods.js b/server/controllers/api/remote/pods.js new file mode 100644 index 000000000..0343bc62e --- /dev/null +++ b/server/controllers/api/remote/pods.js | |||
@@ -0,0 +1,42 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | const express = require('express') | ||
4 | const waterfall = require('async/waterfall') | ||
5 | |||
6 | const db = require('../../../initializers/database') | ||
7 | const middlewares = require('../../../middlewares') | ||
8 | const checkSignature = middlewares.secure.checkSignature | ||
9 | const signatureValidator = middlewares.validators.remote.signature | ||
10 | |||
11 | const router = express.Router() | ||
12 | |||
13 | // Post because this is a secured request | ||
14 | router.post('/remove', | ||
15 | signatureValidator.signature, | ||
16 | checkSignature, | ||
17 | removePods | ||
18 | ) | ||
19 | |||
20 | // --------------------------------------------------------------------------- | ||
21 | |||
22 | module.exports = router | ||
23 | |||
24 | // --------------------------------------------------------------------------- | ||
25 | |||
26 | function removePods (req, res, next) { | ||
27 | const host = req.body.signature.host | ||
28 | |||
29 | waterfall([ | ||
30 | function loadPod (callback) { | ||
31 | db.Pod.loadByHost(host, callback) | ||
32 | }, | ||
33 | |||
34 | function deletePod (pod, callback) { | ||
35 | pod.destroy().asCallback(callback) | ||
36 | } | ||
37 | ], function (err) { | ||
38 | if (err) return next(err) | ||
39 | |||
40 | return res.type('json').status(204).end() | ||
41 | }) | ||
42 | } | ||