From b0c55b9e8604de864a2447ec8074f07b32a1a638 Mon Sep 17 00:00:00 2001 From: velvettear Date: Fri, 25 Mar 2022 12:37:06 +0100 Subject: [PATCH] beautify code --- libs/blinky.js | 2 +- libs/constants.js | 12 ++++++------ libs/info.js | 2 +- libs/logger.js | 25 +++++++++++-------------- 4 files changed, 19 insertions(+), 22 deletions(-) diff --git a/libs/blinky.js b/libs/blinky.js index 2540b4b..1a6050d 100644 --- a/libs/blinky.js +++ b/libs/blinky.js @@ -63,7 +63,7 @@ async function setPedalStatus(pedal) { global.config.blinky.port, 'set', { - blinkstick: "strip", + blinkstick: 'strip', index: pedal.id, color: getPedalColor(pedal.name, isBypassActive(bypass)) } diff --git a/libs/constants.js b/libs/constants.js index ae7ad23..d736701 100644 --- a/libs/constants.js +++ b/libs/constants.js @@ -34,12 +34,12 @@ exports.API_BYPASS_BY_ID = BYPASS + '/' + VARIABLE_ID; exports.API_MIDI = MIDI; exports.API_SYSTEMD = SYSTEMD; -exports.CACHE_BANKS = "banks"; -exports.CACHE_PEDALBOARDS = "pedalboards"; -exports.CACHE_PEDALBOARD_DEFAULT = "pedalboard_default"; -exports.CACHE_PEDALBOARD_CURRENT = "pedalboard_current"; -exports.CACHE_PEDALS = "pedals"; -exports.CACHE_PEDALS_BYPASSED = "pedals_bypassed" +exports.CACHE_BANKS = 'banks'; +exports.CACHE_PEDALBOARDS = 'pedalboards'; +exports.CACHE_PEDALBOARD_DEFAULT = 'pedalboard_default'; +exports.CACHE_PEDALBOARD_CURRENT = 'pedalboard_current'; +exports.CACHE_PEDALS = 'pedals'; +exports.CACHE_PEDALS_BYPASSED = 'pedals_bypassed' exports.PEDALBOARD_DEFAULT = '/var/modep/pedalboards/default.pedalboard'; diff --git a/libs/info.js b/libs/info.js index c4d47d2..d89dc14 100644 --- a/libs/info.js +++ b/libs/info.js @@ -54,7 +54,7 @@ function getMemoryInfo() { async function getTemperature() { try { - return commands.execute("vcgencmd", ["measure_temp"]); + return commands.execute('vcgencmd', ['measure_temp']); } catch (err) { throw new Error(err); } diff --git a/libs/logger.js b/libs/logger.js index b15231d..190d03f 100644 --- a/libs/logger.js +++ b/libs/logger.js @@ -13,20 +13,17 @@ const LOGLEVEL_ERROR = 3; var loglevel = getLogLevel(); var timestamp = getTimestamp(); -function initialize() { - return new Promise((resolve, reject) => { - if (global.config == undefined) { - reject('could not initialize logger, config is undefined'); - } - loglevel = getLogLevel(); - timestamp = getTimestamp(); - resolve(); - }); +async function initialize() { + if (global.config === undefined) { + throw new Error('could not initialize logger, config is undefined'); + } + loglevel = getLogLevel(); + timestamp = getTimestamp(); } // get the loglevel function getLogLevel() { - if (global.config?.log?.level == undefined) { + if (global.config?.log?.level === undefined) { return LOGLEVEL_INFO; } switch (global.config.log.level) { @@ -49,15 +46,15 @@ function getLogLevel() { // get the timestamp format function getTimestamp() { - if (global.config?.log?.format != undefined) { - return global.config.log.format; + if (global.config?.log?.format === undefined) { + return 'DD.MM.YYYY HH:mm:ss:SS'; } - return "DD.MM.YYYY HH:mm:ss:SS"; + return global.config.log.format; } // log a http request - response object function http(object) { - if (object == undefined) { + if (object === undefined) { return; } let message = '[' + object.request.method + ':' + object.code + '] url: \'' + object.request.url + '\'';