diff options
Diffstat (limited to 'server/middlewares')
-rw-r--r-- | server/middlewares/validators/activitypub/index.ts | 3 | ||||
-rw-r--r-- | server/middlewares/validators/activitypub/pods.ts | 38 | ||||
-rw-r--r-- | server/middlewares/validators/index.ts | 1 | ||||
-rw-r--r-- | server/middlewares/validators/pods.ts | 73 |
4 files changed, 1 insertions, 114 deletions
diff --git a/server/middlewares/validators/activitypub/index.ts b/server/middlewares/validators/activitypub/index.ts index f1f26043e..84d1107fc 100644 --- a/server/middlewares/validators/activitypub/index.ts +++ b/server/middlewares/validators/activitypub/index.ts | |||
@@ -1,3 +1,2 @@ | |||
1 | export * from './pods' | 1 | export * from './activity' |
2 | export * from './signature' | 2 | export * from './signature' |
3 | export * from './videos' | ||
diff --git a/server/middlewares/validators/activitypub/pods.ts b/server/middlewares/validators/activitypub/pods.ts deleted file mode 100644 index f917b61ee..000000000 --- a/server/middlewares/validators/activitypub/pods.ts +++ /dev/null | |||
@@ -1,38 +0,0 @@ | |||
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 | } | ||
diff --git a/server/middlewares/validators/index.ts b/server/middlewares/validators/index.ts index 46c00d679..0b7573d4f 100644 --- a/server/middlewares/validators/index.ts +++ b/server/middlewares/validators/index.ts | |||
@@ -2,7 +2,6 @@ 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' | ||
6 | export * from './sort' | 5 | export * from './sort' |
7 | export * from './users' | 6 | export * from './users' |
8 | export * from './videos' | 7 | export * from './videos' |
diff --git a/server/middlewares/validators/pods.ts b/server/middlewares/validators/pods.ts deleted file mode 100644 index 8465fea53..000000000 --- a/server/middlewares/validators/pods.ts +++ /dev/null | |||
@@ -1,73 +0,0 @@ | |||
1 | import { body, param } from 'express-validator/check' | ||
2 | import * as express from 'express' | ||
3 | |||
4 | import { database as db } from '../../initializers/database' | ||
5 | import { checkErrors } from './utils' | ||
6 | import { logger, isEachUniqueHostValid, isTestInstance } from '../../helpers' | ||
7 | import { CONFIG } from '../../initializers' | ||
8 | import { hasFriends } from '../../lib' | ||
9 | |||
10 | const makeFriendsValidator = [ | ||
11 | body('hosts').custom(isEachUniqueHostValid).withMessage('Should have an array of unique hosts'), | ||
12 | |||
13 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
14 | // Force https if the administrator wants to make friends | ||
15 | if (isTestInstance() === false && CONFIG.WEBSERVER.SCHEME === 'http') { | ||
16 | return res.status(400) | ||
17 | .json({ | ||
18 | error: 'Cannot make friends with a non HTTPS web server.' | ||
19 | }) | ||
20 | .end() | ||
21 | } | ||
22 | |||
23 | logger.debug('Checking makeFriends parameters', { parameters: req.body }) | ||
24 | |||
25 | checkErrors(req, res, () => { | ||
26 | hasFriends() | ||
27 | .then(heHasFriends => { | ||
28 | if (heHasFriends === true) { | ||
29 | // We need to quit our friends before make new ones | ||
30 | return res.sendStatus(409) | ||
31 | } | ||
32 | |||
33 | return next() | ||
34 | }) | ||
35 | .catch(err => { | ||
36 | logger.error('Cannot know if we have friends.', err) | ||
37 | res.sendStatus(500) | ||
38 | }) | ||
39 | }) | ||
40 | } | ||
41 | ] | ||
42 | |||
43 | const podRemoveValidator = [ | ||
44 | param('id').isNumeric().not().isEmpty().withMessage('Should have a valid id'), | ||
45 | |||
46 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
47 | logger.debug('Checking podRemoveValidator parameters', { parameters: req.params }) | ||
48 | |||
49 | checkErrors(req, res, () => { | ||
50 | db.Pod.load(req.params.id) | ||
51 | .then(pod => { | ||
52 | if (!pod) { | ||
53 | logger.error('Cannot find pod %d.', req.params.id) | ||
54 | return res.sendStatus(404) | ||
55 | } | ||
56 | |||
57 | res.locals.pod = pod | ||
58 | return next() | ||
59 | }) | ||
60 | .catch(err => { | ||
61 | logger.error('Cannot load pod %d.', req.params.id, err) | ||
62 | res.sendStatus(500) | ||
63 | }) | ||
64 | }) | ||
65 | } | ||
66 | ] | ||
67 | |||
68 | // --------------------------------------------------------------------------- | ||
69 | |||
70 | export { | ||
71 | makeFriendsValidator, | ||
72 | podRemoveValidator | ||
73 | } | ||