]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/validators/activitypub/signature.ts
Optimize SQL requests of watch page API endpoints
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / activitypub / signature.ts
CommitLineData
e4f97bab 1import * as express from 'express'
a2431b7d 2import { body } from 'express-validator/check'
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 = [
12 body('signature.type').custom(isSignatureTypeValid).withMessage('Should have a valid signature type'),
13 body('signature.created').custom(isDateValid).withMessage('Should have a valid signature created date'),
14 body('signature.creator').custom(isSignatureCreatorValid).withMessage('Should have a valid signature creator'),
15 body('signature.signatureValue').custom(isSignatureValueValid).withMessage('Should have a valid signature value'),
16
17 (req: express.Request, res: express.Response, next: express.NextFunction) => {
18 logger.debug('Checking activitypub signature parameter', { parameters: { signature: req.body.signature } })
19
a2431b7d
C
20 if (areValidationErrors(req, res)) return
21
22 return next()
e4f97bab
C
23 }
24]
25
26// ---------------------------------------------------------------------------
27
28export {
29 signatureValidator
30}