|
|
|
@ -7,8 +7,6 @@ const { Resolver } = require("dns");
|
|
|
|
|
const childProcess = require("child_process");
|
|
|
|
|
const iconv = require("iconv-lite");
|
|
|
|
|
const chardet = require("chardet");
|
|
|
|
|
const fs = require("fs");
|
|
|
|
|
const nodeJsUtil = require("util");
|
|
|
|
|
const mqtt = require("mqtt");
|
|
|
|
|
const chroma = require("chroma-js");
|
|
|
|
|
const { badgeConstants } = require("./config");
|
|
|
|
@ -208,7 +206,7 @@ exports.dnsResolve = function (hostname, resolverServer, rrtype) {
|
|
|
|
|
/**
|
|
|
|
|
* Retrieve value of setting based on key
|
|
|
|
|
* @param {string} key Key of setting to retrieve
|
|
|
|
|
* @returns {Promise<Object>} Object representation of setting
|
|
|
|
|
* @returns {Promise<any>} Value
|
|
|
|
|
*/
|
|
|
|
|
exports.setting = async function (key) {
|
|
|
|
|
let value = await R.getCell("SELECT `value` FROM setting WHERE `key` = ? ", [
|
|
|
|
@ -527,32 +525,6 @@ exports.convertToUTF8 = (body) => {
|
|
|
|
|
return str.toString();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let logFile;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
logFile = fs.createWriteStream("./data/error.log", {
|
|
|
|
|
flags: "a"
|
|
|
|
|
});
|
|
|
|
|
} catch (_) { }
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Write error to log file
|
|
|
|
|
* @param {any} error The error to write
|
|
|
|
|
* @param {boolean} outputToConsole Should the error also be output to console?
|
|
|
|
|
*/
|
|
|
|
|
exports.errorLog = (error, outputToConsole = true) => {
|
|
|
|
|
try {
|
|
|
|
|
if (logFile) {
|
|
|
|
|
const dateTime = R.isoDateTime();
|
|
|
|
|
logFile.write(`[${dateTime}] ` + nodeJsUtil.format(error) + "\n");
|
|
|
|
|
|
|
|
|
|
if (outputToConsole) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (_) { }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns a color code in hex format based on a given percentage:
|
|
|
|
|
* 0% => hue = 10 => red
|
|
|
|
|