41 lines
943 B
TypeScript
41 lines
943 B
TypeScript
|
import express = require('express')
|
||
|
import { waterfall } from 'async/waterfall'
|
||
|
|
||
|
const db = require('../../../initializers/database')
|
||
|
import { checkSignature, signatureValidator } from '../../../middlewares'
|
||
|
|
||
|
const remotePodsRouter = express.Router()
|
||
|
|
||
|
// Post because this is a secured request
|
||
|
remotePodsRouter.post('/remove',
|
||
|
signatureValidator,
|
||
|
checkSignature,
|
||
|
removePods
|
||
|
)
|
||
|
|
||
|
// ---------------------------------------------------------------------------
|
||
|
|
||
|
export {
|
||
|
remotePodsRouter
|
||
|
}
|
||
|
|
||
|
// ---------------------------------------------------------------------------
|
||
|
|
||
|
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()
|
||
|
})
|
||
|
}
|