diff options
author | Chocobozzz <me@florianbigard.com> | 2018-10-12 15:26:04 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-10-16 16:41:36 +0200 |
commit | 7ad9b9846c44d198a736183fb186c2039f5236b5 (patch) | |
tree | 9c8456882a261c0522efb507f20e323c2741a0f8 /server/middlewares/validators/server.ts | |
parent | dffd5d127f49eb63d2b2b3133aec75ec1d7e4dcb (diff) | |
download | PeerTube-7ad9b9846c44d198a736183fb186c2039f5236b5.tar.gz PeerTube-7ad9b9846c44d198a736183fb186c2039f5236b5.tar.zst PeerTube-7ad9b9846c44d198a736183fb186c2039f5236b5.zip |
Add ability for users to block an account/instance on server side
Diffstat (limited to 'server/middlewares/validators/server.ts')
-rw-r--r-- | server/middlewares/validators/server.ts | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/server/middlewares/validators/server.ts b/server/middlewares/validators/server.ts new file mode 100644 index 000000000..a491dfeb3 --- /dev/null +++ b/server/middlewares/validators/server.ts | |||
@@ -0,0 +1,33 @@ | |||
1 | import * as express from 'express' | ||
2 | import { logger } from '../../helpers/logger' | ||
3 | import { areValidationErrors } from './utils' | ||
4 | import { isHostValid } from '../../helpers/custom-validators/servers' | ||
5 | import { ServerModel } from '../../models/server/server' | ||
6 | import { body } from 'express-validator/check' | ||
7 | |||
8 | const serverGetValidator = [ | ||
9 | body('host').custom(isHostValid).withMessage('Should have a valid host'), | ||
10 | |||
11 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
12 | logger.debug('Checking serverGetValidator parameters', { parameters: req.body }) | ||
13 | |||
14 | if (areValidationErrors(req, res)) return | ||
15 | |||
16 | const server = await ServerModel.loadByHost(req.body.host) | ||
17 | if (!server) { | ||
18 | return res.status(404) | ||
19 | .send({ error: 'Server host not found.' }) | ||
20 | .end() | ||
21 | } | ||
22 | |||
23 | res.locals.server = server | ||
24 | |||
25 | return next() | ||
26 | } | ||
27 | ] | ||
28 | |||
29 | // --------------------------------------------------------------------------- | ||
30 | |||
31 | export { | ||
32 | serverGetValidator | ||
33 | } | ||