]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - server/middlewares/validators/activitypub/activity.ts
replace numbers with typed http status codes (#3409)
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / activitypub / activity.ts
... / ...
CommitLineData
1import * as express from 'express'
2import { isRootActivityValid } from '../../../helpers/custom-validators/activitypub/activity'
3import { logger } from '../../../helpers/logger'
4import { getServerActor } from '@server/models/application/application'
5import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
6
7async function activityPubValidator (req: express.Request, res: express.Response, next: express.NextFunction) {
8 logger.debug('Checking activity pub parameters')
9
10 if (!isRootActivityValid(req.body)) {
11 logger.warn('Incorrect activity parameters.', { activity: req.body })
12 return res.status(HttpStatusCode.BAD_REQUEST_400)
13 .json({ error: 'Incorrect activity.' })
14 }
15
16 const serverActor = await getServerActor()
17 const remoteActor = res.locals.signature.actor
18 if (serverActor.id === remoteActor.id) {
19 logger.error('Receiving request in INBOX by ourselves!', req.body)
20 return res.status(HttpStatusCode.CONFLICT_409)
21 .end()
22 }
23
24 return next()
25}
26
27// ---------------------------------------------------------------------------
28
29export {
30 activityPubValidator
31}