X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fcustom-validators%2Flogs.ts;h=215dbb0e1319c76f2d5656c6bec2070e7945c644;hb=2a4c0d8bbe29178ae90e776bb9453f86e6d23bd9;hp=0f266ed3b8e4c8dfaf3790ec22280c1eb6fb864f;hpb=610d0be13b3d01f653ef269271dd667a57c85ef2;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/custom-validators/logs.ts b/server/helpers/custom-validators/logs.ts index 0f266ed3b..215dbb0e1 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 = new Set([ 'debug', 'info', 'warn', 'error' ]) +const clientLogLevels = 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 }