]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/middlewares/validators/activitypub/signature.ts
Fix express validator
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / activitypub / signature.ts
index 0ce15c1f6e735a88379eabb736b17037872bc0c1..02b191480b022ba401663e9211b5c5a4f119da37 100644 (file)
@@ -1,25 +1,33 @@
-import { body } from 'express-validator/check'
 import * as express from 'express'
-
+import { body } from 'express-validator'
 import {
-  logger,
-  isDateValid,
-  isSignatureTypeValid,
-  isSignatureCreatorValid,
+  isSignatureCreatorValid, isSignatureTypeValid,
   isSignatureValueValid
-} from '../../../helpers'
-import { checkErrors } from '../utils'
+} from '../../../helpers/custom-validators/activitypub/signature'
+import { isDateValid } from '../../../helpers/custom-validators/misc'
+import { logger } from '../../../helpers/logger'
+import { areValidationErrors } from '../utils'
 
 const signatureValidator = [
-  body('signature.type').custom(isSignatureTypeValid).withMessage('Should have a valid signature type'),
-  body('signature.created').custom(isDateValid).withMessage('Should have a valid signature created date'),
-  body('signature.creator').custom(isSignatureCreatorValid).withMessage('Should have a valid signature creator'),
-  body('signature.signatureValue').custom(isSignatureValueValid).withMessage('Should have a valid signature value'),
+  body('signature.type')
+    .optional()
+    .custom(isSignatureTypeValid).withMessage('Should have a valid signature type'),
+  body('signature.created')
+    .optional()
+    .custom(isDateValid).withMessage('Should have a valid signature created date'),
+  body('signature.creator')
+    .optional()
+    .custom(isSignatureCreatorValid).withMessage('Should have a valid signature creator'),
+  body('signature.signatureValue')
+    .optional()
+    .custom(isSignatureValueValid).withMessage('Should have a valid signature value'),
 
   (req: express.Request, res: express.Response, next: express.NextFunction) => {
     logger.debug('Checking activitypub signature parameter', { parameters: { signature: req.body.signature } })
 
-    checkErrors(req, res, next)
+    if (areValidationErrors(req, res)) return
+
+    return next()
   }
 ]