1
0
Fork 0

Server: move pod remove to remote path

This commit is contained in:
Chocobozzz 2017-03-19 18:56:10 +01:00
parent f148e5edb6
commit 34831b4843
4 changed files with 45 additions and 27 deletions

View file

@ -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)

View file

@ -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)

View 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()
})
}

View file

@ -186,7 +186,7 @@ function quitFriends (callback) {
function announceIQuitMyFriends (pods, callbackAsync) {
const requestParams = {
method: 'POST',
path: '/api/' + constants.API_VERSION + '/pods/remove',
path: '/api/' + constants.API_VERSION + '/remote/pods/remove',
sign: true
}