PeerTube/server/controllers/api/remote/pods.ts

33 lines
911 B
TypeScript
Raw Normal View History

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