diff options
author | Daniel Baumann <daniel@debian.org> | 2024-11-26 09:28:28 +0100 |
---|---|---|
committer | Daniel Baumann <daniel@debian.org> | 2024-11-26 12:25:58 +0100 |
commit | a1882b67c41fe9901a0cd8059b5cc78a5beadec0 (patch) | |
tree | 2a24507c67aa99a15416707b2f7e645142230ed8 /server/check-version.js | |
parent | Initial commit. (diff) | |
download | uptime-kuma-a1882b67c41fe9901a0cd8059b5cc78a5beadec0.tar.xz uptime-kuma-a1882b67c41fe9901a0cd8059b5cc78a5beadec0.zip |
Adding upstream version 2.0.0~beta.0+dfsg.upstream/2.0.0_beta.0+dfsgupstream
Signed-off-by: Daniel Baumann <daniel@debian.org>
Diffstat (limited to 'server/check-version.js')
-rw-r--r-- | server/check-version.js | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/server/check-version.js b/server/check-version.js new file mode 100644 index 0000000..c6d5cfb --- /dev/null +++ b/server/check-version.js @@ -0,0 +1,69 @@ +const { setSetting, setting } = require("./util-server"); +const axios = require("axios"); +const compareVersions = require("compare-versions"); +const { log } = require("../src/util"); + +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 setting("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 setting("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 setSetting("checkUpdate", value); + + clearInterval(interval); + + if (value) { + exports.startInterval(); + } +}; + +exports.socket = null; |