aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/remote/pods.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-10-19 09:43:01 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-10-19 09:43:01 +0200
commit8a02bd0433b7101c5ea36e87a4edb63204d2adec (patch)
treed7ab4b6164aef752c216bd2f22f8b3b270a724b8 /server/controllers/api/remote/pods.ts
parent9fd540562c356cb54b98861d2d9e7d4fbfcd00e0 (diff)
downloadPeerTube-8a02bd0433b7101c5ea36e87a4edb63204d2adec.tar.gz
PeerTube-8a02bd0433b7101c5ea36e87a4edb63204d2adec.tar.zst
PeerTube-8a02bd0433b7101c5ea36e87a4edb63204d2adec.zip
Add pod list endpoint with pagination, sort...
Diffstat (limited to 'server/controllers/api/remote/pods.ts')
-rw-r--r--server/controllers/api/remote/pods.ts45
1 files changed, 42 insertions, 3 deletions
diff --git a/server/controllers/api/remote/pods.ts b/server/controllers/api/remote/pods.ts
index 69bbd4378..6f7b5f651 100644
--- a/server/controllers/api/remote/pods.ts
+++ b/server/controllers/api/remote/pods.ts
@@ -1,18 +1,34 @@
1import * as express from 'express' 1import * as express from 'express'
2 2
3import { database as db } from '../../../initializers/database' 3import { database as db } from '../../../initializers/database'
4import { checkSignature, signatureValidator } from '../../../middlewares' 4import {
5import { PodSignature } from '../../../../shared' 5 checkSignature,
6 signatureValidator,
7 setBodyHostPort,
8 remotePodsAddValidator
9} from '../../../middlewares'
10import { sendOwnedVideosToPod } from '../../../lib'
11import { getMyPublicCert, getFormattedObjects } from '../../../helpers'
12import { CONFIG } from '../../../initializers'
13import { PodInstance } from '../../../models'
14import { PodSignature, Pod as FormattedPod } from '../../../../shared'
6 15
7const remotePodsRouter = express.Router() 16const remotePodsRouter = express.Router()
8 17
9// Post because this is a secured request
10remotePodsRouter.post('/remove', 18remotePodsRouter.post('/remove',
11 signatureValidator, 19 signatureValidator,
12 checkSignature, 20 checkSignature,
13 removePods 21 removePods
14) 22)
15 23
24remotePodsRouter.post('/list', remotePodsList)
25
26remotePodsRouter.post('/add',
27 setBodyHostPort, // We need to modify the host before running the validator!
28 remotePodsAddValidator,
29 addPods
30)
31
16// --------------------------------------------------------------------------- 32// ---------------------------------------------------------------------------
17 33
18export { 34export {
@@ -21,6 +37,29 @@ export {
21 37
22// --------------------------------------------------------------------------- 38// ---------------------------------------------------------------------------
23 39
40function addPods (req: express.Request, res: express.Response, next: express.NextFunction) {
41 const information = req.body
42
43 const pod = db.Pod.build(information)
44 pod.save()
45 .then(podCreated => {
46 return sendOwnedVideosToPod(podCreated.id)
47 })
48 .then(() => {
49 return getMyPublicCert()
50 })
51 .then(cert => {
52 return res.json({ cert: cert, email: CONFIG.ADMIN.EMAIL })
53 })
54 .catch(err => next(err))
55}
56
57function remotePodsList (req: express.Request, res: express.Response, next: express.NextFunction) {
58 db.Pod.list()
59 .then(podsList => res.json(getFormattedObjects<FormattedPod, PodInstance>(podsList, podsList.length)))
60 .catch(err => next(err))
61}
62
24function removePods (req: express.Request, res: express.Response, next: express.NextFunction) { 63function removePods (req: express.Request, res: express.Response, next: express.NextFunction) {
25 const signature: PodSignature = req.body.signature 64 const signature: PodSignature = req.body.signature
26 const host = signature.host 65 const host = signature.host