]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - server/middlewares/validators/logs.ts
Add ability for admins to set default p2p policy
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / logs.ts
... / ...
CommitLineData
1import express from 'express'
2import { query } from 'express-validator'
3import { isStringArray } from '@server/helpers/custom-validators/search'
4import { isValidLogLevel } from '../../helpers/custom-validators/logs'
5import { isDateValid, toArray } from '../../helpers/custom-validators/misc'
6import { logger } from '../../helpers/logger'
7import { areValidationErrors } from './shared'
8
9const getLogsValidator = [
10 query('startDate')
11 .custom(isDateValid).withMessage('Should have a start date that conforms to ISO 8601'),
12 query('level')
13 .optional()
14 .custom(isValidLogLevel).withMessage('Should have a valid level'),
15 query('tagsOneOf')
16 .optional()
17 .customSanitizer(toArray)
18 .custom(isStringArray).withMessage('Should have a valid one of tags array'),
19 query('endDate')
20 .optional()
21 .custom(isDateValid).withMessage('Should have an end date that conforms to ISO 8601'),
22
23 (req: express.Request, res: express.Response, next: express.NextFunction) => {
24 logger.debug('Checking getLogsValidator parameters.', { parameters: req.query })
25
26 if (areValidationErrors(req, res)) return
27
28 return next()
29 }
30]
31
32const getAuditLogsValidator = [
33 query('startDate')
34 .custom(isDateValid).withMessage('Should have a start date that conforms to ISO 8601'),
35 query('endDate')
36 .optional()
37 .custom(isDateValid).withMessage('Should have a end date that conforms to ISO 8601'),
38
39 (req: express.Request, res: express.Response, next: express.NextFunction) => {
40 logger.debug('Checking getAuditLogsValidator parameters.', { parameters: req.query })
41
42 if (areValidationErrors(req, res)) return
43
44 return next()
45 }
46]
47
48// ---------------------------------------------------------------------------
49
50export {
51 getLogsValidator,
52 getAuditLogsValidator
53}