aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/remote/pods.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/remote/pods.ts')
-rw-r--r--server/controllers/api/remote/pods.ts69
1 files changed, 0 insertions, 69 deletions
diff --git a/server/controllers/api/remote/pods.ts b/server/controllers/api/remote/pods.ts
deleted file mode 100644
index 326eb61ac..000000000
--- a/server/controllers/api/remote/pods.ts
+++ /dev/null
@@ -1,69 +0,0 @@
1import * as express from 'express'
2
3import { database as db } from '../../../initializers/database'
4import {
5 checkSignature,
6 signatureValidator,
7 setBodyHostPort,
8 remotePodsAddValidator,
9 asyncMiddleware
10} from '../../../middlewares'
11import { sendOwnedDataToPod } from '../../../lib'
12import { getMyPublicCert, getFormattedObjects } from '../../../helpers'
13import { CONFIG } from '../../../initializers'
14import { PodInstance } from '../../../models'
15import { PodSignature, Pod as FormattedPod } from '../../../../shared'
16
17const remotePodsRouter = express.Router()
18
19remotePodsRouter.post('/remove',
20 signatureValidator,
21 checkSignature,
22 asyncMiddleware(removePods)
23)
24
25remotePodsRouter.post('/list',
26 asyncMiddleware(remotePodsList)
27)
28
29remotePodsRouter.post('/add',
30 setBodyHostPort, // We need to modify the host before running the validator!
31 remotePodsAddValidator,
32 asyncMiddleware(addPods)
33)
34
35// ---------------------------------------------------------------------------
36
37export {
38 remotePodsRouter
39}
40
41// ---------------------------------------------------------------------------
42
43async function addPods (req: express.Request, res: express.Response, next: express.NextFunction) {
44 const information = req.body
45
46 const pod = db.Pod.build(information)
47 const podCreated = await pod.save()
48
49 await sendOwnedDataToPod(podCreated.id)
50
51 const cert = await getMyPublicCert()
52 return res.json({ cert, email: CONFIG.ADMIN.EMAIL })
53}
54
55async function remotePodsList (req: express.Request, res: express.Response, next: express.NextFunction) {
56 const pods = await db.Pod.list()
57
58 return res.json(getFormattedObjects<FormattedPod, PodInstance>(pods, pods.length))
59}
60
61async function removePods (req: express.Request, res: express.Response, next: express.NextFunction) {
62 const signature: PodSignature = req.body.signature
63 const host = signature.host
64
65 const pod = await db.Pod.loadByHost(host)
66 await pod.destroy()
67
68 return res.type('json').status(204).end()
69}