]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/validators/logs.ts
Add tags to AP rate logger
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / logs.ts
CommitLineData
fd8710b8
C
1import * as express from 'express'
2import { logger } from '../../helpers/logger'
3import { areValidationErrors } from './utils'
4import { isDateValid } from '../../helpers/custom-validators/misc'
c8861d5d 5import { query } from 'express-validator'
fd8710b8
C
6import { isValidLogLevel } from '../../helpers/custom-validators/logs'
7
8const getLogsValidator = [
9 query('startDate')
70330f63 10 .custom(isDateValid).withMessage('Should have a start date that conforms to ISO 8601'),
fd8710b8
C
11 query('level')
12 .optional()
13 .custom(isValidLogLevel).withMessage('Should have a valid level'),
14 query('endDate')
15 .optional()
70330f63 16 .custom(isDateValid).withMessage('Should have an end date that conforms to ISO 8601'),
fd8710b8
C
17
18 (req: express.Request, res: express.Response, next: express.NextFunction) => {
19 logger.debug('Checking getLogsValidator parameters.', { parameters: req.query })
20
21 if (areValidationErrors(req, res)) return
22
23 return next()
24 }
25]
26
566c125d
C
27const getAuditLogsValidator = [
28 query('startDate')
70330f63 29 .custom(isDateValid).withMessage('Should have a start date that conforms to ISO 8601'),
566c125d
C
30 query('endDate')
31 .optional()
70330f63 32 .custom(isDateValid).withMessage('Should have a end date that conforms to ISO 8601'),
566c125d
C
33
34 (req: express.Request, res: express.Response, next: express.NextFunction) => {
35 logger.debug('Checking getAuditLogsValidator parameters.', { parameters: req.query })
36
37 if (areValidationErrors(req, res)) return
38
39 return next()
40 }
41]
42
fd8710b8
C
43// ---------------------------------------------------------------------------
44
45export {
566c125d
C
46 getLogsValidator,
47 getAuditLogsValidator
fd8710b8 48}