]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/validators/activitypub/activity.ts
Add ability to change the homepage
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / activitypub / activity.ts
CommitLineData
0d0e8dd0 1import * as express from 'express'
350e31d6 2import { body } from 'express-validator/check'
da854ddd
C
3import { isRootActivityValid } from '../../../helpers/custom-validators/activitypub/activity'
4import { logger } from '../../../helpers/logger'
285fe7c9
C
5import { getServerActor } from '../../../helpers/utils'
6import { ActorModel } from '../../../models/activitypub/actor'
a2431b7d 7import { areValidationErrors } from '../utils'
0d0e8dd0
C
8
9const 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
30export {
31 activityPubValidator
32}