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 { areValidationErrors } from './shared'
18 const createClientLogValidator = [
20 .custom(isValidClientLogMessage),
26 .custom(isValidClientLogLevel),
30 .custom(isValidClientLogStackTrace),
34 .custom(isValidClientLogMeta),
38 .custom(isValidClientLogUserAgent),
40 (req: express.Request, res: express.Response, next: express.NextFunction) => {
41 if (CONFIG.LOG.ACCEPT_CLIENT_LOG !== true) {
42 return res.sendStatus(HttpStatusCode.FORBIDDEN_403)
45 if (areValidationErrors(req, res)) return
51 const getLogsValidator = [
53 .custom(isDateValid).withMessage('Should have a start date that conforms to ISO 8601'),
56 .custom(isValidLogLevel),
59 .customSanitizer(toArray)
60 .custom(isStringArray).withMessage('Should have a valid one of tags array'),
63 .custom(isDateValid).withMessage('Should have an end date that conforms to ISO 8601'),
65 (req: express.Request, res: express.Response, next: express.NextFunction) => {
66 if (areValidationErrors(req, res)) return
72 const getAuditLogsValidator = [
74 .custom(isDateValid).withMessage('Should have a start date that conforms to ISO 8601'),
77 .custom(isDateValid).withMessage('Should have a end date that conforms to ISO 8601'),
79 (req: express.Request, res: express.Response, next: express.NextFunction) => {
80 if (areValidationErrors(req, res)) return
86 // ---------------------------------------------------------------------------
90 getAuditLogsValidator,
91 createClientLogValidator