From 000cbeb0ce1921f36314ea904fcf5b23e61bd179 Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Sun, 1 May 2022 18:25:52 +0800 Subject: [PATCH 1/5] Lower check-linters node version to 14, add Node.js 18, set timeout 15mins for each job --- .github/workflows/auto-test.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/auto-test.yml b/.github/workflows/auto-test.yml index 82451f378..a7a01684a 100644 --- a/.github/workflows/auto-test.yml +++ b/.github/workflows/auto-test.yml @@ -13,11 +13,12 @@ jobs: auto-test: needs: [ check-linters ] runs-on: ${{ matrix.os }} + timeout-minutes: 15 strategy: matrix: os: [macos-latest, ubuntu-latest, windows-latest] - node: [14, 16, 17] + node: [ 14, 16, 17, 18 ] # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ steps: @@ -45,7 +46,7 @@ jobs: - name: Use Node.js LTS uses: actions/setup-node@v3 with: - node-version: 16 + node-version: 14 cache: 'npm' - run: npm install - run: npm run lint From 15820c69379b66ad032524223871b9c0f9b1a637 Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Sun, 1 May 2022 19:45:00 +0800 Subject: [PATCH 2/5] Update SQLite --- package-lock.json | 18 +++++++++--------- package.json | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9bedab9fe..729a1c4c6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,19 +1,19 @@ { "name": "uptime-kuma", - "version": "1.15.0", + "version": "1.15.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "uptime-kuma", - "version": "1.15.0", + "version": "1.15.1", "license": "MIT", "dependencies": { "@fortawesome/fontawesome-svg-core": "~1.2.36", "@fortawesome/free-regular-svg-icons": "~5.15.4", "@fortawesome/free-solid-svg-icons": "~5.15.4", "@fortawesome/vue-fontawesome": "~3.0.0-5", - "@louislam/sqlite3": "~15.0.3", + "@louislam/sqlite3": "~15.0.6", "@popperjs/core": "~2.10.2", "args-parser": "~1.3.0", "axios": "~0.26.1", @@ -2697,9 +2697,9 @@ } }, "node_modules/@louislam/sqlite3": { - "version": "15.0.3", - "resolved": "https://registry.npmjs.org/@louislam/sqlite3/-/sqlite3-15.0.3.tgz", - "integrity": "sha512-rCH6PIaa+TgBzpTRnqBKUa4H/5G2hIk5ukYK5rXxK+8hVGykRin3UMGzGejrPzIKzDnZGByIF0XD4ndi6lprRQ==", + "version": "15.0.6", + "resolved": "https://registry.npmjs.org/@louislam/sqlite3/-/sqlite3-15.0.6.tgz", + "integrity": "sha512-+HF/4OEy+yakYzJlSPJbLDtf499t0s0eaglXC9y3Oa9OBZ+dKAaTW5+Ft1RCvfUJLFw/oyYjHtMsg9V+7NT05g==", "hasInstallScript": true, "dependencies": { "@mapbox/node-pre-gyp": "^1.0.0", @@ -18665,9 +18665,9 @@ } }, "@louislam/sqlite3": { - "version": "15.0.3", - "resolved": "https://registry.npmjs.org/@louislam/sqlite3/-/sqlite3-15.0.3.tgz", - "integrity": "sha512-rCH6PIaa+TgBzpTRnqBKUa4H/5G2hIk5ukYK5rXxK+8hVGykRin3UMGzGejrPzIKzDnZGByIF0XD4ndi6lprRQ==", + "version": "15.0.6", + "resolved": "https://registry.npmjs.org/@louislam/sqlite3/-/sqlite3-15.0.6.tgz", + "integrity": "sha512-+HF/4OEy+yakYzJlSPJbLDtf499t0s0eaglXC9y3Oa9OBZ+dKAaTW5+Ft1RCvfUJLFw/oyYjHtMsg9V+7NT05g==", "requires": { "@mapbox/node-pre-gyp": "^1.0.0", "node-addon-api": "^4.2.0", diff --git a/package.json b/package.json index 6b21096bc..52e30e9e3 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,7 @@ "@fortawesome/free-regular-svg-icons": "~5.15.4", "@fortawesome/free-solid-svg-icons": "~5.15.4", "@fortawesome/vue-fontawesome": "~3.0.0-5", - "@louislam/sqlite3": "~15.0.3", + "@louislam/sqlite3": "~15.0.6", "@popperjs/core": "~2.10.2", "args-parser": "~1.3.0", "axios": "~0.26.1", From 5c852db1cfc809063d88f86f5bc4d9fc1164a298 Mon Sep 17 00:00:00 2001 From: Adam Stachowicz Date: Mon, 2 May 2022 01:23:05 +0200 Subject: [PATCH 3/5] Fix actions/setup-node task name Addendum to 000cbeb0ce1921f36314ea904fcf5b23e61bd179 --- .github/workflows/auto-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/auto-test.yml b/.github/workflows/auto-test.yml index a7a01684a..d26b76e68 100644 --- a/.github/workflows/auto-test.yml +++ b/.github/workflows/auto-test.yml @@ -43,7 +43,7 @@ jobs: - run: git config --global core.autocrlf false # Mainly for Windows - uses: actions/checkout@v3 - - name: Use Node.js LTS + - name: Use Node.js 14 uses: actions/setup-node@v3 with: node-version: 14 From 429ad384d081ee8e228b192ff82ae27c45dfdd70 Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Fri, 6 May 2022 14:41:34 +0800 Subject: [PATCH 4/5] Fix hardcoded path for error.log and move errorLog() to UptimeKumaServer.errorLog() --- server/model/monitor.js | 5 +++-- server/server.js | 4 ++-- server/uptime-kuma-server.js | 29 ++++++++++++++++++++++++++++- server/util-server.js | 30 +----------------------------- 4 files changed, 34 insertions(+), 34 deletions(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index e106f7ab3..f2d16524b 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -7,7 +7,7 @@ dayjs.extend(timezone); const axios = require("axios"); const { Prometheus } = require("../prometheus"); const { log, UP, DOWN, PENDING, flipStatus, TimeLogger } = require("../../src/util"); -const { tcping, ping, dnsResolve, checkCertificate, checkStatusCode, getTotalClientInRoom, setting, errorLog, mqttAsync } = require("../util-server"); +const { tcping, ping, dnsResolve, checkCertificate, checkStatusCode, getTotalClientInRoom, setting, mqttAsync } = require("../util-server"); const { R } = require("redbean-node"); const { BeanModel } = require("redbean-node/dist/bean-model"); const { Notification } = require("../notification"); @@ -15,6 +15,7 @@ const { Proxy } = require("../proxy"); const { demoMode } = require("../config"); const version = require("../../package.json").version; const apicache = require("../modules/apicache"); +const { UptimeKumaServer } = require("../uptime-kuma-server"); /** * status: @@ -521,7 +522,7 @@ class Monitor extends BeanModel { await beat(); } catch (e) { console.trace(e); - errorLog(e, false); + UptimeKumaServer.errorLog(e, false); log.error("monitor", "Please report to https://github.com/louislam/uptime-kuma/issues"); if (! this.isStop) { diff --git a/server/server.js b/server/server.js index 11c59edbb..79cb21026 100644 --- a/server/server.js +++ b/server/server.js @@ -60,7 +60,7 @@ log.info("server", "Importing this project modules"); log.debug("server", "Importing Monitor"); const Monitor = require("./model/monitor"); log.debug("server", "Importing Settings"); -const { getSettings, setSettings, setting, initJWTSecret, checkLogin, startUnitTest, FBSD, errorLog, doubleCheckPassword } = require("./util-server"); +const { getSettings, setSettings, setting, initJWTSecret, checkLogin, startUnitTest, FBSD, doubleCheckPassword } = require("./util-server"); log.debug("server", "Importing Notification"); const { Notification } = require("./notification"); @@ -1694,6 +1694,6 @@ gracefulShutdown(server.httpServer, { // Catch unexpected errors here process.addListener("unhandledRejection", (error, promise) => { console.trace(error); - errorLog(error, false); + UptimeKumaServer.errorLog(error, false); console.error("If you keep encountering errors, please report to https://github.com/louislam/uptime-kuma/issues"); }); diff --git a/server/uptime-kuma-server.js b/server/uptime-kuma-server.js index 1cc740646..d0c968e73 100644 --- a/server/uptime-kuma-server.js +++ b/server/uptime-kuma-server.js @@ -5,13 +5,14 @@ const http = require("http"); const { Server } = require("socket.io"); const { R } = require("redbean-node"); const { log } = require("../src/util"); +const Database = require("./database"); +const util = require("util"); /** * `module.exports` (alias: `server`) should be inside this class, in order to avoid circular dependency issue. * @type {UptimeKumaServer} */ class UptimeKumaServer { - /** * * @type {UptimeKumaServer} @@ -83,6 +84,32 @@ class UptimeKumaServer { return result; } + + /** + * Write error to log file + * @param {any} error The error to write + * @param {boolean} outputToConsole Should the error also be output to console? + */ + static errorLog(error, outputToConsole = true) { + const errorLogStream = fs.createWriteStream(Database.dataDir + "/error.log", { + flags: "a" + }); + + errorLogStream.on("error", () => { + log.info("", "Cannot write to error.log"); + }); + + if (errorLogStream) { + const dateTime = R.isoDateTime(); + errorLogStream.write(`[${dateTime}] ` + util.format(error) + "\n"); + + if (outputToConsole) { + console.error(error); + } + } + + errorLogStream.end(); + } } module.exports = { diff --git a/server/util-server.js b/server/util-server.js index 39a2d9040..985143d51 100644 --- a/server/util-server.js +++ b/server/util-server.js @@ -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"); // From ping-lite @@ -206,7 +204,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 representation of setting + * @returns {Promise} Value */ exports.setting = async function (key) { let value = await R.getCell("SELECT `value` FROM setting WHERE `key` = ? ", [ @@ -524,29 +522,3 @@ exports.convertToUTF8 = (body) => { const str = iconv.decode(body, guessEncoding); 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 (_) { } -}; From 8b0813ceff9f47672a5ddfc7e020ce27ee37e7ec Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Fri, 6 May 2022 14:52:09 +0800 Subject: [PATCH 5/5] Fix #1596 hopefully --- src/layouts/Layout.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/layouts/Layout.vue b/src/layouts/Layout.vue index c7076221f..9688cdc28 100644 --- a/src/layouts/Layout.vue +++ b/src/layouts/Layout.vue @@ -33,7 +33,7 @@