1 import * as express from 'express'
3 import { database as db } from '../../../initializers/database'
9 } from '../../../middlewares'
10 import { sendOwnedVideosToPod } from '../../../lib'
11 import { getMyPublicCert, getFormattedObjects } from '../../../helpers'
12 import { CONFIG } from '../../../initializers'
13 import { PodInstance } from '../../../models'
14 import { PodSignature, Pod as FormattedPod } from '../../../../shared'
16 const remotePodsRouter = express.Router()
18 remotePodsRouter.post('/remove',
24 remotePodsRouter.post('/list', remotePodsList)
26 remotePodsRouter.post('/add',
27 setBodyHostPort, // We need to modify the host before running the validator!
28 remotePodsAddValidator,
32 // ---------------------------------------------------------------------------
38 // ---------------------------------------------------------------------------
40 function addPods (req: express.Request, res: express.Response, next: express.NextFunction) {
41 const information = req.body
43 const pod = db.Pod.build(information)
46 return sendOwnedVideosToPod(podCreated.id)
49 return getMyPublicCert()
52 return res.json({ cert: cert, email: CONFIG.ADMIN.EMAIL })
54 .catch(err => next(err))
57 function remotePodsList (req: express.Request, res: express.Response, next: express.NextFunction) {
59 .then(podsList => res.json(getFormattedObjects<FormattedPod, PodInstance>(podsList, podsList.length)))
60 .catch(err => next(err))
63 function removePods (req: express.Request, res: express.Response, next: express.NextFunction) {
64 const signature: PodSignature = req.body.signature
65 const host = signature.host
67 db.Pod.loadByHost(host)
68 .then(pod => pod.destroy())
69 .then(() => res.type('json').status(204).end())
70 .catch(err => next(err))