You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
uptime-kuma/server/check-version.js

70 lines
1.8 KiB

3 years ago
const axios = require("axios");
const compareVersions = require("compare-versions");
const { log } = require("../src/util");
const { Settings } = require("./settings");
3 years ago
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";
3 years ago
let interval;
exports.startInterval = () => {
let check = async () => {
if (await Settings.get("checkUpdate") === false) {
return;
}
log.debug("update-checker", "Retrieving latest versions");
3 years ago
try {
const res = await axios.get(UPDATE_CHECKER_LATEST_VERSION_URL);
3 years ago
// 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;
3 years ago
}
} catch (_) {
log.info("update-checker", "Failed to check for new versions");
}
3 years ago
};
check();
interval = setInterval(check, UPDATE_CHECKER_INTERVAL_MS);
3 years ago
};
/**
* Enable the check update feature
* @param {boolean} value Should the check update feature be enabled?
* @returns {Promise<void>}
*/
3 years ago
exports.enableCheckUpdate = async (value) => {
await Settings.set("checkUpdate", value);
3 years ago
clearInterval(interval);
if (value) {
exports.startInterval();
}
};
exports.socket = null;