uptime-kuma/server/check-version.js
Cassandra Beelen e85789ecae
chore: addressing of simple deprecations surrounding Settings and log
Co-authored-by: Frank Elsinga <frank@elsinga.de>
Closes: #4391

Squashed commit of the following:

commit 828d2a73d4
Merge: 10f771cf dd758903
Author: Frank Elsinga <frank@elsinga.de>
Date:   Fri Sep 13 22:51:25 2024 +0800

    Merge branch 'master' into deprecations

commit 10f771cfc6
Author: Frank Elsinga <frank@elsinga.de>
Date:   Thu Jan 18 22:36:12 2024 +0100

    formatting fixes

commit d737b19e2f
Author: Frank Elsinga <frank@elsinga.de>
Date:   Thu Jan 18 21:27:30 2024 +0100

    migrated all settings to use the `Settings` class

commit c5e26e993e
Author: Frank Elsinga <frank@elsinga.de>
Date:   Thu Jan 18 21:04:44 2024 +0100

    removed the deprecated logging functionality

* fix(server/model/monitor): duplicate `Settings.set` for `tlsExpiryNotifyDays`

* fix(eslint): minor linter complaints & a typo
2024-10-10 16:48:10 +02:00

69 lines
1.8 KiB
JavaScript

const axios = require("axios");
const compareVersions = require("compare-versions");
const { log } = require("../src/util");
const { Settings } = require("./settings");
exports.version = require("../package.json").version;
exports.latestVersion = null;
// How much time in ms to wait between update checks
const UPDATE_CHECKER_INTERVAL_MS = 1000 * 60 * 60 * 48;
const UPDATE_CHECKER_LATEST_VERSION_URL = "https://uptime.kuma.pet/version";
let interval;
exports.startInterval = () => {
let check = async () => {
if (await Settings.get("checkUpdate") === false) {
return;
}
log.debug("update-checker", "Retrieving latest versions");
try {
const res = await axios.get(UPDATE_CHECKER_LATEST_VERSION_URL);
// For debug
if (process.env.TEST_CHECK_VERSION === "1") {
res.data.slow = "1000.0.0";
}
let checkBeta = await Settings.get("checkBeta");
if (checkBeta && res.data.beta) {
if (compareVersions.compare(res.data.beta, res.data.slow, ">")) {
exports.latestVersion = res.data.beta;
return;
}
}
if (res.data.slow) {
exports.latestVersion = res.data.slow;
}
} catch (_) {
log.info("update-checker", "Failed to check for new versions");
}
};
check();
interval = setInterval(check, UPDATE_CHECKER_INTERVAL_MS);
};
/**
* Enable the check update feature
* @param {boolean} value Should the check update feature be enabled?
* @returns {Promise<void>}
*/
exports.enableCheckUpdate = async (value) => {
await Settings.set("checkUpdate", value);
clearInterval(interval);
if (value) {
exports.startInterval();
}
};
exports.socket = null;