]>
Commit | Line | Data |
---|---|---|
0d0e8dd0 | 1 | import * as express from 'express' |
350e31d6 | 2 | import { body } from 'express-validator/check' |
da854ddd C |
3 | import { isRootActivityValid } from '../../../helpers/custom-validators/activitypub/activity' |
4 | import { logger } from '../../../helpers/logger' | |
285fe7c9 C |
5 | import { getServerActor } from '../../../helpers/utils' |
6 | import { ActorModel } from '../../../models/activitypub/actor' | |
a2431b7d | 7 | import { areValidationErrors } from '../utils' |
0d0e8dd0 | 8 | |
ee28cdf1 C |
9 | async function activityPubValidator (req: express.Request, res: express.Response, next: express.NextFunction) { |
10 | logger.debug('Checking activity pub parameters') | |
0d0e8dd0 | 11 | |
ee28cdf1 C |
12 | if (!isRootActivityValid(req.body)) { |
13 | logger.warn('Incorrect activity parameters.', { activity: req.body }) | |
14 | return res.status(400).json({ error: 'Incorrect activity.' }) | |
15 | } | |
285fe7c9 | 16 | |
ee28cdf1 C |
17 | const serverActor = await getServerActor() |
18 | const remoteActor = res.locals.signature.actor as ActorModel | |
19 | if (serverActor.id === remoteActor.id) { | |
20 | logger.error('Receiving request in INBOX by ourselves!', req.body) | |
21 | return res.status(409).end() | |
0d0e8dd0 | 22 | } |
ee28cdf1 C |
23 | |
24 | return next() | |
25 | } | |
0d0e8dd0 C |
26 | |
27 | // --------------------------------------------------------------------------- | |
28 | ||
29 | export { | |
30 | activityPubValidator | |
31 | } |