@ -9,7 +9,8 @@
// Frontend uses util.ts
* /
Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
exports . localToUTC = exports . utcToLocal = exports . utcToISODateTime = exports . isoToUTCDateTime = exports . parseTimeFromTimeObject = exports . parseTimeObject = exports . getMaintenanceRelativeURL = exports . getMonitorRelativeURL = exports . genSecret = exports . getCryptoRandomInt = exports . getRandomInt = exports . getRandomArbitrary = exports . TimeLogger = exports . polyfill = exports . log = exports . debug = exports . ucfirst = exports . sleep = exports . flipStatus = exports . MIN _INTERVAL _SECOND = exports . MAX _INTERVAL _SECOND = exports . SQL _DATETIME _FORMAT _WITHOUT _SECOND = exports . SQL _DATETIME _FORMAT = exports . SQL _DATE _FORMAT = exports . STATUS _PAGE _MAINTENANCE = exports . STATUS _PAGE _PARTIAL _DOWN = exports . STATUS _PAGE _ALL _UP = exports . STATUS _PAGE _ALL _DOWN = exports . MAINTENANCE = exports . PENDING = exports . UP = exports . DOWN = exports . appName = exports . isDev = void 0 ;
exports . debug = exports . ucfirst = exports . sleep = exports . flipStatus = exports . CONSOLE _STYLE _BgGray = exports . CONSOLE _STYLE _BgWhite = exports . CONSOLE _STYLE _BgCyan = exports . CONSOLE _STYLE _BgMagenta = exports . CONSOLE _STYLE _BgBlue = exports . CONSOLE _STYLE _BgYellow = exports . CONSOLE _STYLE _BgGreen = exports . CONSOLE _STYLE _BgRed = exports . CONSOLE _STYLE _BgBlack = exports . CONSOLE _STYLE _FgPink = exports . CONSOLE _STYLE _FgBrown = exports . CONSOLE _STYLE _FgViolet = exports . CONSOLE _STYLE _FgLightBlue = exports . CONSOLE _STYLE _FgLightGreen = exports . CONSOLE _STYLE _FgOrange = exports . CONSOLE _STYLE _FgGray = exports . CONSOLE _STYLE _FgWhite = exports . CONSOLE _STYLE _FgCyan = exports . CONSOLE _STYLE _FgMagenta = exports . CONSOLE _STYLE _FgBlue = exports . CONSOLE _STYLE _FgYellow = exports . CONSOLE _STYLE _FgGreen = exports . CONSOLE _STYLE _FgRed = exports . CONSOLE _STYLE _FgBlack = exports . CONSOLE _STYLE _Hidden = exports . CONSOLE _STYLE _Reverse = exports . CONSOLE _STYLE _Blink = exports . CONSOLE _STYLE _Underscore = exports . CONSOLE _STYLE _Dim = exports . CONSOLE _STYLE _Bright = exports . CONSOLE _STYLE _Reset = exports . MIN _INTERVAL _SECOND = exports . MAX _INTERVAL _SECOND = exports . SQL _DATETIME _FORMAT _WITHOUT _SECOND = exports . SQL _DATETIME _FORMAT = exports . SQL _DATE _FORMAT = exports . STATUS _PAGE _MAINTENANCE = exports . STATUS _PAGE _PARTIAL _DOWN = exports . STATUS _PAGE _ALL _UP = exports . STATUS _PAGE _ALL _DOWN = exports . MAINTENANCE = exports . PENDING = exports . UP = exports . DOWN = exports . appName = exports . isDev = void 0 ;
exports . intHash = exports . localToUTC = exports . utcToLocal = exports . utcToISODateTime = exports . isoToUTCDateTime = exports . parseTimeFromTimeObject = exports . parseTimeObject = exports . getMaintenanceRelativeURL = exports . getMonitorRelativeURL = exports . genSecret = exports . getCryptoRandomInt = exports . getRandomInt = exports . getRandomArbitrary = exports . TimeLogger = exports . polyfill = exports . log = void 0 ;
const dayjs = require ( "dayjs" ) ;
exports . isDev = process . env . NODE _ENV === "development" ;
exports . appName = "Uptime Kuma" ;
@ -26,6 +27,55 @@ exports.SQL_DATETIME_FORMAT = "YYYY-MM-DD HH:mm:ss";
exports . SQL _DATETIME _FORMAT _WITHOUT _SECOND = "YYYY-MM-DD HH:mm" ;
exports . MAX _INTERVAL _SECOND = 2073600 ;
exports . MIN _INTERVAL _SECOND = 20 ;
exports . CONSOLE _STYLE _Reset = "\x1b[0m" ;
exports . CONSOLE _STYLE _Bright = "\x1b[1m" ;
exports . CONSOLE _STYLE _Dim = "\x1b[2m" ;
exports . CONSOLE _STYLE _Underscore = "\x1b[4m" ;
exports . CONSOLE _STYLE _Blink = "\x1b[5m" ;
exports . CONSOLE _STYLE _Reverse = "\x1b[7m" ;
exports . CONSOLE _STYLE _Hidden = "\x1b[8m" ;
exports . CONSOLE _STYLE _FgBlack = "\x1b[30m" ;
exports . CONSOLE _STYLE _FgRed = "\x1b[31m" ;
exports . CONSOLE _STYLE _FgGreen = "\x1b[32m" ;
exports . CONSOLE _STYLE _FgYellow = "\x1b[33m" ;
exports . CONSOLE _STYLE _FgBlue = "\x1b[34m" ;
exports . CONSOLE _STYLE _FgMagenta = "\x1b[35m" ;
exports . CONSOLE _STYLE _FgCyan = "\x1b[36m" ;
exports . CONSOLE _STYLE _FgWhite = "\x1b[37m" ;
exports . CONSOLE _STYLE _FgGray = "\x1b[90m" ;
exports . CONSOLE _STYLE _FgOrange = "\x1b[38;5;208m" ;
exports . CONSOLE _STYLE _FgLightGreen = "\x1b[38;5;119m" ;
exports . CONSOLE _STYLE _FgLightBlue = "\x1b[38;5;117m" ;
exports . CONSOLE _STYLE _FgViolet = "\x1b[38;5;141m" ;
exports . CONSOLE _STYLE _FgBrown = "\x1b[38;5;130m" ;
exports . CONSOLE _STYLE _FgPink = "\x1b[38;5;219m" ;
exports . CONSOLE _STYLE _BgBlack = "\x1b[40m" ;
exports . CONSOLE _STYLE _BgRed = "\x1b[41m" ;
exports . CONSOLE _STYLE _BgGreen = "\x1b[42m" ;
exports . CONSOLE _STYLE _BgYellow = "\x1b[43m" ;
exports . CONSOLE _STYLE _BgBlue = "\x1b[44m" ;
exports . CONSOLE _STYLE _BgMagenta = "\x1b[45m" ;
exports . CONSOLE _STYLE _BgCyan = "\x1b[46m" ;
exports . CONSOLE _STYLE _BgWhite = "\x1b[47m" ;
exports . CONSOLE _STYLE _BgGray = "\x1b[100m" ;
const consoleModuleColors = [
exports . CONSOLE _STYLE _FgCyan ,
exports . CONSOLE _STYLE _FgGreen ,
exports . CONSOLE _STYLE _FgLightGreen ,
exports . CONSOLE _STYLE _FgBlue ,
exports . CONSOLE _STYLE _FgLightBlue ,
exports . CONSOLE _STYLE _FgMagenta ,
exports . CONSOLE _STYLE _FgOrange ,
exports . CONSOLE _STYLE _FgViolet ,
exports . CONSOLE _STYLE _FgBrown ,
exports . CONSOLE _STYLE _FgPink ,
] ;
const consoleLevelColors = {
"INFO" : exports . CONSOLE _STYLE _FgCyan ,
"WARN" : exports . CONSOLE _STYLE _FgYellow ,
"ERROR" : exports . CONSOLE _STYLE _FgRed ,
"DEBUG" : exports . CONSOLE _STYLE _FgGray ,
} ;
function flipStatus ( s ) {
if ( s === exports . UP ) {
return exports . DOWN ;
@ -85,23 +135,30 @@ class Logger {
else {
now = dayjs ( ) . format ( ) ;
}
const formattedMessage = ( typeof msg === "string" ) ? ` ${ now } [ ${ module } ] ${ level } : ${ msg } ` : msg ;
const levelColor = consoleLevelColors [ level ] ;
const moduleColor = consoleModuleColors [ intHash ( module , consoleModuleColors . length ) ] ;
let timePart = exports . CONSOLE _STYLE _FgCyan + now + exports . CONSOLE _STYLE _Reset ;
let modulePart = "[" + moduleColor + module + exports . CONSOLE _STYLE _Reset + "]" ;
let levelPart = levelColor + ` ${ level } : ` + exports . CONSOLE _STYLE _Reset ;
if ( level === "INFO" ) {
console . info ( formattedMessage ) ;
console . info ( timePart, modulePart , levelPart , msg ) ;
}
else if ( level === "WARN" ) {
console . warn ( formattedMessage ) ;
console . warn ( timePart, modulePart , levelPart , msg ) ;
}
else if ( level === "ERROR" ) {
console . error ( formattedMessage ) ;
let msgPart = exports . CONSOLE _STYLE _FgRed + msg + exports . CONSOLE _STYLE _Reset ;
console . error ( timePart , modulePart , levelPart , msgPart ) ;
}
else if ( level === "DEBUG" ) {
if ( exports . isDev ) {
console . log ( formattedMessage ) ;
timePart = exports . CONSOLE _STYLE _FgGray + now + exports . CONSOLE _STYLE _Reset ;
let msgPart = exports . CONSOLE _STYLE _FgGray + msg + exports . CONSOLE _STYLE _Reset ;
console . debug ( timePart , modulePart , levelPart , msgPart ) ;
}
}
else {
console . log ( formattedMessage ) ;
console . log ( timePart, modulePart , msg ) ;
}
}
info ( module , msg ) {
@ -269,3 +326,11 @@ function localToUTC(input, format = exports.SQL_DATETIME_FORMAT) {
return dayjs ( input ) . utc ( ) . format ( format ) ;
}
exports . localToUTC = localToUTC ;
function intHash ( str , length = 10 ) {
let hash = 0 ;
for ( let i = 0 ; i < str . length ; i ++ ) {
hash += str . charCodeAt ( i ) ;
}
return ( hash % length + length ) % length ;
}
exports . intHash = intHash ;