diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-11-13 18:48:28 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-11-27 19:40:51 +0100 |
commit | ce548a10db3822c415b30ea0edb59e02a460734a (patch) | |
tree | b39127c62101b5bf47e0a8a3c30bc70d6449824d /server/middlewares/validators | |
parent | 7a7724e66e4533523083e7336cd0d0c747c4a33b (diff) | |
download | PeerTube-ce548a10db3822c415b30ea0edb59e02a460734a.tar.gz PeerTube-ce548a10db3822c415b30ea0edb59e02a460734a.tar.zst PeerTube-ce548a10db3822c415b30ea0edb59e02a460734a.zip |
Send follow/accept
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r-- | server/middlewares/validators/index.ts | 1 | ||||
-rw-r--r-- | server/middlewares/validators/pods.ts | 32 |
2 files changed, 33 insertions, 0 deletions
diff --git a/server/middlewares/validators/index.ts b/server/middlewares/validators/index.ts index 0b7573d4f..46c00d679 100644 --- a/server/middlewares/validators/index.ts +++ b/server/middlewares/validators/index.ts | |||
@@ -2,6 +2,7 @@ export * from './account' | |||
2 | export * from './oembed' | 2 | export * from './oembed' |
3 | export * from './activitypub' | 3 | export * from './activitypub' |
4 | export * from './pagination' | 4 | export * from './pagination' |
5 | export * from './pods' | ||
5 | export * from './sort' | 6 | export * from './sort' |
6 | export * from './users' | 7 | export * from './users' |
7 | export * from './videos' | 8 | export * from './videos' |
diff --git a/server/middlewares/validators/pods.ts b/server/middlewares/validators/pods.ts new file mode 100644 index 000000000..e17369a6f --- /dev/null +++ b/server/middlewares/validators/pods.ts | |||
@@ -0,0 +1,32 @@ | |||
1 | import * as express from 'express' | ||
2 | import { body } from 'express-validator/check' | ||
3 | import { isEachUniqueHostValid } from '../../helpers/custom-validators/pods' | ||
4 | import { isTestInstance } from '../../helpers/core-utils' | ||
5 | import { CONFIG } from '../../initializers/constants' | ||
6 | import { logger } from '../../helpers/logger' | ||
7 | import { checkErrors } from './utils' | ||
8 | |||
9 | const followValidator = [ | ||
10 | body('hosts').custom(isEachUniqueHostValid).withMessage('Should have an array of unique hosts'), | ||
11 | |||
12 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
13 | // Force https if the administrator wants to make friends | ||
14 | if (isTestInstance() === false && CONFIG.WEBSERVER.SCHEME === 'http') { | ||
15 | return res.status(400) | ||
16 | .json({ | ||
17 | error: 'Cannot follow non HTTPS web server.' | ||
18 | }) | ||
19 | .end() | ||
20 | } | ||
21 | |||
22 | logger.debug('Checking follow parameters', { parameters: req.body }) | ||
23 | |||
24 | checkErrors(req, res, next) | ||
25 | } | ||
26 | ] | ||
27 | |||
28 | // --------------------------------------------------------------------------- | ||
29 | |||
30 | export { | ||
31 | followValidator | ||
32 | } | ||