From 42b40636991b97fe818007fab19091764fc5db73 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 15 Jul 2022 15:30:14 +0200 Subject: Add ability for client to create server logs --- server/helpers/custom-validators/logs.ts | 36 ++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) (limited to 'server/helpers') diff --git a/server/helpers/custom-validators/logs.ts b/server/helpers/custom-validators/logs.ts index 0f266ed3b..41d45cbb2 100644 --- a/server/helpers/custom-validators/logs.ts +++ b/server/helpers/custom-validators/logs.ts @@ -1,14 +1,42 @@ +import validator from 'validator' +import { CONSTRAINTS_FIELDS } from '@server/initializers/constants' +import { ClientLogLevel, ServerLogLevel } from '@shared/models' import { exists } from './misc' -import { LogLevel } from '../../../shared/models/server/log-level.type' -const logLevels: LogLevel[] = [ 'debug', 'info', 'warn', 'error' ] +const serverLogLevels: Set = new Set([ 'debug', 'info', 'warn', 'error' ]) +const clientLogLevels: Set = new Set([ 'warn', 'error' ]) function isValidLogLevel (value: any) { - return exists(value) && logLevels.includes(value) + return exists(value) && serverLogLevels.has(value) +} + +function isValidClientLogMessage (value: any) { + return typeof value === 'string' && validator.isLength(value, CONSTRAINTS_FIELDS.LOGS.CLIENT_MESSAGE) +} + +function isValidClientLogLevel (value: any) { + return exists(value) && clientLogLevels.has(value) +} + +function isValidClientLogStackTrace (value: any) { + return typeof value === 'string' && validator.isLength(value, CONSTRAINTS_FIELDS.LOGS.CLIENT_STACK_TRACE) +} + +function isValidClientLogMeta (value: any) { + return typeof value === 'string' && validator.isLength(value, CONSTRAINTS_FIELDS.LOGS.CLIENT_META) +} + +function isValidClientLogUserAgent (value: any) { + return typeof value === 'string' && validator.isLength(value, CONSTRAINTS_FIELDS.LOGS.CLIENT_USER_AGENT) } // --------------------------------------------------------------------------- export { - isValidLogLevel + isValidLogLevel, + isValidClientLogMessage, + isValidClientLogStackTrace, + isValidClientLogMeta, + isValidClientLogLevel, + isValidClientLogUserAgent } -- cgit v1.2.3