1 import express from 'express'
2 import { body, query } from 'express-validator'
3 import { isUrlValid } from '@server/helpers/custom-validators/activitypub/misc'
4 import { isStringArray } from '@server/helpers/custom-validators/search'
5 import { CONFIG } from '@server/initializers/config'
6 import { HttpStatusCode } from '@shared/models'
9 isValidClientLogMessage,
11 isValidClientLogStackTrace,
12 isValidClientLogUserAgent,
14 } from '../../helpers/custom-validators/logs'
15 import { isDateValid, toArray } from '../../helpers/custom-validators/misc'
16 import { logger } from '../../helpers/logger'
17 import { areValidationErrors } from './shared'
19 const createClientLogValidator = [
21 .custom(isValidClientLogMessage),
27 .custom(isValidClientLogLevel),
31 .custom(isValidClientLogStackTrace),
35 .custom(isValidClientLogMeta),
39 .custom(isValidClientLogUserAgent),
41 (req: express.Request, res: express.Response, next: express.NextFunction) => {
42 logger.debug('Checking createClientLogValidator parameters.', { parameters: req.query })
44 if (CONFIG.LOG.ACCEPT_CLIENT_LOG !== true) {
45 return res.sendStatus(HttpStatusCode.FORBIDDEN_403)
48 if (areValidationErrors(req, res)) return
54 const getLogsValidator = [
56 .custom(isDateValid).withMessage('Should have a start date that conforms to ISO 8601'),
59 .custom(isValidLogLevel),
62 .customSanitizer(toArray)
63 .custom(isStringArray).withMessage('Should have a valid one of tags array'),
66 .custom(isDateValid).withMessage('Should have an end date that conforms to ISO 8601'),
68 (req: express.Request, res: express.Response, next: express.NextFunction) => {
69 logger.debug('Checking getLogsValidator parameters.', { parameters: req.query })
71 if (areValidationErrors(req, res)) return
77 const getAuditLogsValidator = [
79 .custom(isDateValid).withMessage('Should have a start date that conforms to ISO 8601'),
82 .custom(isDateValid).withMessage('Should have a end date that conforms to ISO 8601'),
84 (req: express.Request, res: express.Response, next: express.NextFunction) => {
85 logger.debug('Checking getAuditLogsValidator parameters.', { parameters: req.query })
87 if (areValidationErrors(req, res)) return
93 // ---------------------------------------------------------------------------
97 getAuditLogsValidator,
98 createClientLogValidator