diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-10-19 09:43:01 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-10-19 09:43:01 +0200 |
commit | 8a02bd0433b7101c5ea36e87a4edb63204d2adec (patch) | |
tree | d7ab4b6164aef752c216bd2f22f8b3b270a724b8 /server/middlewares/validators/remote | |
parent | 9fd540562c356cb54b98861d2d9e7d4fbfcd00e0 (diff) | |
download | PeerTube-8a02bd0433b7101c5ea36e87a4edb63204d2adec.tar.gz PeerTube-8a02bd0433b7101c5ea36e87a4edb63204d2adec.tar.zst PeerTube-8a02bd0433b7101c5ea36e87a4edb63204d2adec.zip |
Add pod list endpoint with pagination, sort...
Diffstat (limited to 'server/middlewares/validators/remote')
-rw-r--r-- | server/middlewares/validators/remote/index.ts | 1 | ||||
-rw-r--r-- | server/middlewares/validators/remote/pods.ts | 38 |
2 files changed, 39 insertions, 0 deletions
diff --git a/server/middlewares/validators/remote/index.ts b/server/middlewares/validators/remote/index.ts index d0d7740b1..f1f26043e 100644 --- a/server/middlewares/validators/remote/index.ts +++ b/server/middlewares/validators/remote/index.ts | |||
@@ -1,2 +1,3 @@ | |||
1 | export * from './pods' | ||
1 | export * from './signature' | 2 | export * from './signature' |
2 | export * from './videos' | 3 | export * from './videos' |
diff --git a/server/middlewares/validators/remote/pods.ts b/server/middlewares/validators/remote/pods.ts new file mode 100644 index 000000000..f917b61ee --- /dev/null +++ b/server/middlewares/validators/remote/pods.ts | |||
@@ -0,0 +1,38 @@ | |||
1 | import { body } from 'express-validator/check' | ||
2 | import * as express from 'express' | ||
3 | |||
4 | import { database as db } from '../../../initializers' | ||
5 | import { isHostValid, logger } from '../../../helpers' | ||
6 | import { checkErrors } from '../utils' | ||
7 | |||
8 | const remotePodsAddValidator = [ | ||
9 | body('host').custom(isHostValid).withMessage('Should have a host'), | ||
10 | body('email').isEmail().withMessage('Should have an email'), | ||
11 | body('publicKey').not().isEmpty().withMessage('Should have a public key'), | ||
12 | |||
13 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
14 | logger.debug('Checking podsAdd parameters', { parameters: req.body }) | ||
15 | |||
16 | checkErrors(req, res, () => { | ||
17 | db.Pod.loadByHost(req.body.host) | ||
18 | .then(pod => { | ||
19 | // Pod with this host already exists | ||
20 | if (pod) { | ||
21 | return res.sendStatus(409) | ||
22 | } | ||
23 | |||
24 | return next() | ||
25 | }) | ||
26 | .catch(err => { | ||
27 | logger.error('Cannot load pod by host.', err) | ||
28 | res.sendStatus(500) | ||
29 | }) | ||
30 | }) | ||
31 | } | ||
32 | ] | ||
33 | |||
34 | // --------------------------------------------------------------------------- | ||
35 | |||
36 | export { | ||
37 | remotePodsAddValidator | ||
38 | } | ||