2017-06-05 14:53:49 -05:00
|
|
|
import * as express from 'express'
|
2017-03-19 12:56:10 -05:00
|
|
|
|
2017-05-22 13:58:25 -05:00
|
|
|
import { database as db } from '../../../initializers/database'
|
2017-05-15 15:22:03 -05:00
|
|
|
import { checkSignature, signatureValidator } from '../../../middlewares'
|
2017-03-19 12:56:10 -05:00
|
|
|
|
2017-05-15 15:22:03 -05:00
|
|
|
const remotePodsRouter = express.Router()
|
2017-03-19 12:56:10 -05:00
|
|
|
|
|
|
|
// Post because this is a secured request
|
2017-05-15 15:22:03 -05:00
|
|
|
remotePodsRouter.post('/remove',
|
|
|
|
signatureValidator,
|
2017-03-19 12:56:10 -05:00
|
|
|
checkSignature,
|
|
|
|
removePods
|
|
|
|
)
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2017-05-15 15:22:03 -05:00
|
|
|
export {
|
|
|
|
remotePodsRouter
|
|
|
|
}
|
2017-03-19 12:56:10 -05:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2017-06-10 15:15:25 -05:00
|
|
|
function removePods (req: express.Request, res: express.Response, next: express.NextFunction) {
|
2017-03-19 12:56:10 -05:00
|
|
|
const host = req.body.signature.host
|
|
|
|
|
2017-07-05 06:26:25 -05:00
|
|
|
db.Pod.loadByHost(host)
|
|
|
|
.then(pod => {
|
|
|
|
return pod.destroy()
|
|
|
|
})
|
|
|
|
.then(() => res.type('json').status(204).end())
|
|
|
|
.catch(err => next(err))
|
2017-03-19 12:56:10 -05:00
|
|
|
}
|