aboutsummaryrefslogblamecommitdiffhomepage
path: root/server/controllers/api/remote/pods.ts
blob: 69bbd43780b4e8babcb395451f84f9ce12959aa3 (plain) (tree)
1
2
3
4
5
6
7
8
9
                                  
 
                                                               
                                                                         
                                                 
 
                                         

                                         

                                





                                                                              


                  


                                                                              
                                                                                               

                                                    
 
                         
                               

                                                   
 
import * as express from 'express'

import { database as db } from '../../../initializers/database'
import { checkSignature, signatureValidator } from '../../../middlewares'
import { PodSignature } from '../../../../shared'

const remotePodsRouter = express.Router()

// Post because this is a secured request
remotePodsRouter.post('/remove',
  signatureValidator,
  checkSignature,
  removePods
)

// ---------------------------------------------------------------------------

export {
  remotePodsRouter
}

// ---------------------------------------------------------------------------

function removePods (req: express.Request, res: express.Response, next: express.NextFunction) {
  const signature: PodSignature = req.body.signature
  const host = signature.host

  db.Pod.loadByHost(host)
    .then(pod => pod.destroy())
    .then(() => res.type('json').status(204).end())
    .catch(err => next(err))
}