X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmiddlewares%2Fvalidators%2Flogs.ts;h=901d8ca64f684032b7be6ba3de65b12419d01c9d;hb=743dab5517d4501f6b35cfc795de6c8b6f41ebb3;hp=07f3f552f40bbe076f75cffb4a46439981d8de5d;hpb=c8861d5dc0436ef4342ce517241e3591fa256a13;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/middlewares/validators/logs.ts b/server/middlewares/validators/logs.ts index 07f3f552f..901d8ca64 100644 --- a/server/middlewares/validators/logs.ts +++ b/server/middlewares/validators/logs.ts @@ -1,19 +1,24 @@ -import * as express from 'express' -import { logger } from '../../helpers/logger' -import { areValidationErrors } from './utils' -import { isDateValid } from '../../helpers/custom-validators/misc' +import express from 'express' import { query } from 'express-validator' +import { isStringArray } from '@server/helpers/custom-validators/search' import { isValidLogLevel } from '../../helpers/custom-validators/logs' +import { isDateValid, toArray } from '../../helpers/custom-validators/misc' +import { logger } from '../../helpers/logger' +import { areValidationErrors } from './shared' const getLogsValidator = [ query('startDate') - .custom(isDateValid).withMessage('Should have a valid start date'), + .custom(isDateValid).withMessage('Should have a start date that conforms to ISO 8601'), query('level') .optional() .custom(isValidLogLevel).withMessage('Should have a valid level'), + query('tagsOneOf') + .optional() + .customSanitizer(toArray) + .custom(isStringArray).withMessage('Should have a valid one of tags array'), query('endDate') .optional() - .custom(isDateValid).withMessage('Should have a valid end date'), + .custom(isDateValid).withMessage('Should have an end date that conforms to ISO 8601'), (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking getLogsValidator parameters.', { parameters: req.query }) @@ -24,8 +29,25 @@ const getLogsValidator = [ } ] +const getAuditLogsValidator = [ + query('startDate') + .custom(isDateValid).withMessage('Should have a start date that conforms to ISO 8601'), + query('endDate') + .optional() + .custom(isDateValid).withMessage('Should have a end date that conforms to ISO 8601'), + + (req: express.Request, res: express.Response, next: express.NextFunction) => { + logger.debug('Checking getAuditLogsValidator parameters.', { parameters: req.query }) + + if (areValidationErrors(req, res)) return + + return next() + } +] + // --------------------------------------------------------------------------- export { - getLogsValidator + getLogsValidator, + getAuditLogsValidator }