Server: move pod remove to remote path
This commit is contained in:
parent
f148e5edb6
commit
34831b4843
4 changed files with 45 additions and 27 deletions
|
@ -13,9 +13,7 @@ const middlewares = require('../../middlewares')
|
||||||
const admin = middlewares.admin
|
const admin = middlewares.admin
|
||||||
const oAuth = middlewares.oauth
|
const oAuth = middlewares.oauth
|
||||||
const podsMiddleware = middlewares.pods
|
const podsMiddleware = middlewares.pods
|
||||||
const checkSignature = middlewares.secure.checkSignature
|
|
||||||
const validators = middlewares.validators.pods
|
const validators = middlewares.validators.pods
|
||||||
const signatureValidator = middlewares.validators.remote.signature
|
|
||||||
|
|
||||||
const router = express.Router()
|
const router = express.Router()
|
||||||
|
|
||||||
|
@ -37,12 +35,6 @@ router.get('/quitfriends',
|
||||||
admin.ensureIsAdmin,
|
admin.ensureIsAdmin,
|
||||||
quitFriends
|
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()
|
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) {
|
function quitFriends (req, res, next) {
|
||||||
friends.quitFriends(function (err) {
|
friends.quitFriends(function (err) {
|
||||||
if (err) return next(err)
|
if (err) return next(err)
|
||||||
|
|
|
@ -6,8 +6,10 @@ const utils = require('../../../helpers/utils')
|
||||||
|
|
||||||
const router = express.Router()
|
const router = express.Router()
|
||||||
|
|
||||||
|
const podsRemoteController = require('./pods')
|
||||||
const videosRemoteController = require('./videos')
|
const videosRemoteController = require('./videos')
|
||||||
|
|
||||||
|
router.use('/pods', podsRemoteController)
|
||||||
router.use('/videos', videosRemoteController)
|
router.use('/videos', videosRemoteController)
|
||||||
router.use('/*', utils.badRequest)
|
router.use('/*', utils.badRequest)
|
||||||
|
|
||||||
|
|
42
server/controllers/api/remote/pods.js
Normal file
42
server/controllers/api/remote/pods.js
Normal file
|
@ -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()
|
||||||
|
})
|
||||||
|
}
|
|
@ -186,7 +186,7 @@ function quitFriends (callback) {
|
||||||
function announceIQuitMyFriends (pods, callbackAsync) {
|
function announceIQuitMyFriends (pods, callbackAsync) {
|
||||||
const requestParams = {
|
const requestParams = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
path: '/api/' + constants.API_VERSION + '/pods/remove',
|
path: '/api/' + constants.API_VERSION + '/remote/pods/remove',
|
||||||
sign: true
|
sign: true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue