]>
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 C |
8 | |
9 | const activityPubValidator = [ | |
350e31d6 | 10 | body('').custom((value, { req }) => isRootActivityValid(req.body)), |
0d0e8dd0 | 11 | |
285fe7c9 | 12 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
fef2c716 | 13 | logger.debug('Checking activity pub parameters') |
0d0e8dd0 | 14 | |
a2431b7d C |
15 | if (areValidationErrors(req, res)) return |
16 | ||
285fe7c9 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) | |
e3bb78a2 | 21 | return res.status(409).end() |
285fe7c9 C |
22 | } |
23 | ||
a2431b7d | 24 | return next() |
0d0e8dd0 C |
25 | } |
26 | ] | |
27 | ||
28 | // --------------------------------------------------------------------------- | |
29 | ||
30 | export { | |
31 | activityPubValidator | |
32 | } |