X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fcustom-validators%2Flogs.ts;h=41d45cbb23f8510fa1fb70d5e11d86b5852d3b6c;hb=edacb640332eae37665551d35bf29160707336f0;hp=0f266ed3b8e4c8dfaf3790ec22280c1eb6fb864f;hpb=bdd428a6d9138d751f8cde82867022a93f1a76cc;p=github%2FChocobozzz%2FPeerTube.git 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 }