]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/validators/logs.ts
Remove unnecessary logs
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / logs.ts
CommitLineData
41fb13c3 1import express from 'express'
42b40636
C
2import { body, query } from 'express-validator'
3import { isUrlValid } from '@server/helpers/custom-validators/activitypub/misc'
64553e88 4import { isStringArray } from '@server/helpers/custom-validators/search'
42b40636
C
5import { CONFIG } from '@server/initializers/config'
6import { HttpStatusCode } from '@shared/models'
7import {
8 isValidClientLogLevel,
9 isValidClientLogMessage,
10 isValidClientLogMeta,
11 isValidClientLogStackTrace,
12 isValidClientLogUserAgent,
13 isValidLogLevel
14} from '../../helpers/custom-validators/logs'
64553e88 15import { isDateValid, toArray } from '../../helpers/custom-validators/misc'
10363c74 16import { areValidationErrors } from './shared'
fd8710b8 17
42b40636
C
18const createClientLogValidator = [
19 body('message')
396f6f01 20 .custom(isValidClientLogMessage),
42b40636
C
21
22 body('url')
396f6f01 23 .custom(isUrlValid),
42b40636
C
24
25 body('level')
396f6f01 26 .custom(isValidClientLogLevel),
42b40636
C
27
28 body('stackTrace')
29 .optional()
396f6f01 30 .custom(isValidClientLogStackTrace),
42b40636
C
31
32 body('meta')
33 .optional()
396f6f01 34 .custom(isValidClientLogMeta),
42b40636
C
35
36 body('userAgent')
37 .optional()
396f6f01 38 .custom(isValidClientLogUserAgent),
42b40636
C
39
40 (req: express.Request, res: express.Response, next: express.NextFunction) => {
42b40636
C
41 if (CONFIG.LOG.ACCEPT_CLIENT_LOG !== true) {
42 return res.sendStatus(HttpStatusCode.FORBIDDEN_403)
43 }
44
45 if (areValidationErrors(req, res)) return
46
47 return next()
48 }
49]
50
fd8710b8
C
51const getLogsValidator = [
52 query('startDate')
70330f63 53 .custom(isDateValid).withMessage('Should have a start date that conforms to ISO 8601'),
fd8710b8
C
54 query('level')
55 .optional()
396f6f01 56 .custom(isValidLogLevel),
64553e88
C
57 query('tagsOneOf')
58 .optional()
59 .customSanitizer(toArray)
60 .custom(isStringArray).withMessage('Should have a valid one of tags array'),
fd8710b8
C
61 query('endDate')
62 .optional()
70330f63 63 .custom(isDateValid).withMessage('Should have an end date that conforms to ISO 8601'),
fd8710b8
C
64
65 (req: express.Request, res: express.Response, next: express.NextFunction) => {
fd8710b8
C
66 if (areValidationErrors(req, res)) return
67
68 return next()
69 }
70]
71
566c125d
C
72const getAuditLogsValidator = [
73 query('startDate')
70330f63 74 .custom(isDateValid).withMessage('Should have a start date that conforms to ISO 8601'),
566c125d
C
75 query('endDate')
76 .optional()
70330f63 77 .custom(isDateValid).withMessage('Should have a end date that conforms to ISO 8601'),
566c125d
C
78
79 (req: express.Request, res: express.Response, next: express.NextFunction) => {
566c125d
C
80 if (areValidationErrors(req, res)) return
81
82 return next()
83 }
84]
85
fd8710b8
C
86// ---------------------------------------------------------------------------
87
88export {
566c125d 89 getLogsValidator,
42b40636
C
90 getAuditLogsValidator,
91 createClientLogValidator
fd8710b8 92}