From 34831b4843c161248109fb10876c1600578491de Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Sun, 19 Mar 2017 18:56:10 +0100 Subject: Server: move pod remove to remote path --- server/controllers/api/pods.js | 26 --------------------- server/controllers/api/remote/index.js | 2 ++ server/controllers/api/remote/pods.js | 42 ++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 26 deletions(-) create mode 100644 server/controllers/api/remote/pods.js (limited to 'server/controllers') 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') const admin = middlewares.admin const oAuth = middlewares.oauth const podsMiddleware = middlewares.pods -const checkSignature = middlewares.secure.checkSignature const validators = middlewares.validators.pods -const signatureValidator = middlewares.validators.remote.signature const router = express.Router() @@ -37,12 +35,6 @@ router.get('/quitfriends', admin.ensureIsAdmin, quitFriends ) -// Post because this is a secured request -router.post('/remove', - signatureValidator.signature, - checkSignature, - removePods -) // --------------------------------------------------------------------------- @@ -108,24 +100,6 @@ function makeFriends (req, res, next) { res.type('json').status(204).end() } -function removePods (req, res, next) { - const host = req.body.signature.host - - waterfall([ - function loadPod (callback) { - db.Pod.loadByHost(host, callback) - }, - - function deletePod (pod, callback) { - pod.destroy().asCallback(callback) - } - ], function (err) { - if (err) return next(err) - - return res.type('json').status(204).end() - }) -} - function quitFriends (req, res, next) { friends.quitFriends(function (err) { 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') const router = express.Router() +const podsRemoteController = require('./pods') const videosRemoteController = require('./videos') +router.use('/pods', podsRemoteController) router.use('/videos', videosRemoteController) router.use('/*', utils.badRequest) 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 @@ +'use strict' + +const express = require('express') +const waterfall = require('async/waterfall') + +const db = require('../../../initializers/database') +const middlewares = require('../../../middlewares') +const checkSignature = middlewares.secure.checkSignature +const signatureValidator = middlewares.validators.remote.signature + +const router = express.Router() + +// Post because this is a secured request +router.post('/remove', + signatureValidator.signature, + checkSignature, + removePods +) + +// --------------------------------------------------------------------------- + +module.exports = router + +// --------------------------------------------------------------------------- + +function removePods (req, res, next) { + const host = req.body.signature.host + + waterfall([ + function loadPod (callback) { + db.Pod.loadByHost(host, callback) + }, + + function deletePod (pod, callback) { + pod.destroy().asCallback(callback) + } + ], function (err) { + if (err) return next(err) + + return res.type('json').status(204).end() + }) +} -- cgit v1.2.3