]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/validators/activitypub/signature.ts
Fix filters on playlists
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / activitypub / signature.ts
CommitLineData
41fb13c3 1import express from 'express'
c8861d5d 2import { body } from 'express-validator'
da854ddd 3import {
10363c74
C
4 isSignatureCreatorValid,
5 isSignatureTypeValid,
da854ddd
C
6 isSignatureValueValid
7} from '../../../helpers/custom-validators/activitypub/signature'
3fd3ab2d 8import { isDateValid } from '../../../helpers/custom-validators/misc'
da854ddd 9import { logger } from '../../../helpers/logger'
10363c74 10import { areValidationErrors } from '../shared'
e4f97bab
C
11
12const signatureValidator = [
41f2ebae
C
13 body('signature.type')
14 .optional()
396f6f01 15 .custom(isSignatureTypeValid),
41f2ebae
C
16 body('signature.created')
17 .optional()
70330f63 18 .custom(isDateValid).withMessage('Should have a signature created date that conforms to ISO 8601'),
41f2ebae
C
19 body('signature.creator')
20 .optional()
396f6f01 21 .custom(isSignatureCreatorValid),
41f2ebae
C
22 body('signature.signatureValue')
23 .optional()
396f6f01 24 .custom(isSignatureValueValid),
e4f97bab
C
25
26 (req: express.Request, res: express.Response, next: express.NextFunction) => {
e7053b1d 27 logger.debug('Checking Linked Data Signature parameter', { parameters: { signature: req.body.signature } })
e4f97bab 28
a85d5303 29 if (areValidationErrors(req, res, { omitLog: true })) return
a2431b7d
C
30
31 return next()
e4f97bab
C
32 }
33]
34
35// ---------------------------------------------------------------------------
36
37export {
38 signatureValidator
39}