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 { arrayify } from '@shared/core-utils'
7 import { HttpStatusCode } from '@shared/models'
10 isValidClientLogMessage,
12 isValidClientLogStackTrace,
13 isValidClientLogUserAgent,
15 } from '../../helpers/custom-validators/logs'
16 import { isDateValid } from '../../helpers/custom-validators/misc'
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 if (CONFIG.LOG.ACCEPT_CLIENT_LOG !== true) {
43 return res.sendStatus(HttpStatusCode.FORBIDDEN_403)
46 if (areValidationErrors(req, res)) return
52 const getLogsValidator = [
54 .custom(isDateValid).withMessage('Should have a start date that conforms to ISO 8601'),
57 .custom(isValidLogLevel),
60 .customSanitizer(arrayify)
61 .custom(isStringArray).withMessage('Should have a valid one of tags array'),
64 .custom(isDateValid).withMessage('Should have an end date that conforms to ISO 8601'),
66 (req: express.Request, res: express.Response, next: express.NextFunction) => {
67 if (areValidationErrors(req, res)) return
73 const getAuditLogsValidator = [
75 .custom(isDateValid).withMessage('Should have a start date that conforms to ISO 8601'),
78 .custom(isDateValid).withMessage('Should have a end date that conforms to ISO 8601'),
80 (req: express.Request, res: express.Response, next: express.NextFunction) => {
81 if (areValidationErrors(req, res)) return
87 // ---------------------------------------------------------------------------
91 getAuditLogsValidator,
92 createClientLogValidator