]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/validators/activitypub/signature.ts
Don't skip all threads on AP fetcher error
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / activitypub / signature.ts
CommitLineData
e4f97bab 1import * as express from 'express'
c8861d5d 2import { body } from 'express-validator'
da854ddd
C
3import {
4 isSignatureCreatorValid, isSignatureTypeValid,
5 isSignatureValueValid
6} from '../../../helpers/custom-validators/activitypub/signature'
3fd3ab2d 7import { isDateValid } from '../../../helpers/custom-validators/misc'
da854ddd 8import { logger } from '../../../helpers/logger'
a2431b7d 9import { areValidationErrors } from '../utils'
e4f97bab
C
10
11const signatureValidator = [
41f2ebae
C
12 body('signature.type')
13 .optional()
14 .custom(isSignatureTypeValid).withMessage('Should have a valid signature type'),
15 body('signature.created')
16 .optional()
17 .custom(isDateValid).withMessage('Should have a valid signature created date'),
18 body('signature.creator')
19 .optional()
20 .custom(isSignatureCreatorValid).withMessage('Should have a valid signature creator'),
21 body('signature.signatureValue')
22 .optional()
23 .custom(isSignatureValueValid).withMessage('Should have a valid signature value'),
e4f97bab
C
24
25 (req: express.Request, res: express.Response, next: express.NextFunction) => {
26 logger.debug('Checking activitypub signature parameter', { parameters: { signature: req.body.signature } })
27
a2431b7d
C
28 if (areValidationErrors(req, res)) return
29
30 return next()
e4f97bab
C
31 }
32]
33
34// ---------------------------------------------------------------------------
35
36export {
37 signatureValidator
38}