mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-11-23 23:04:04 +00:00
Fixed update checker making requests to uptime.kuma.pet even when turned off (#2281)
* fix: update checker - fixed bug where it would make the request to uptime.kuma.pet regardless of the `checkUpdate` config; - defined constants in the top of the document for easier configuration/documentation; - removed unnecessary compareVersions: we were comparing the same var on both sides res.data.beta, so it will always be equal. * improvement: better logging and added doc * improved UPDATE_CHECKER_INTERVAL_MS const --------- Co-authored-by: Louis Lam <louislam@users.noreply.github.com>
This commit is contained in:
parent
a0736e04b2
commit
bd5496d267
1 changed files with 16 additions and 8 deletions
|
@ -1,27 +1,33 @@
|
||||||
const { setSetting, setting } = require("./util-server");
|
const { setSetting, setting } = require("./util-server");
|
||||||
const axios = require("axios");
|
const axios = require("axios");
|
||||||
const compareVersions = require("compare-versions");
|
const compareVersions = require("compare-versions");
|
||||||
|
const { log } = require("../src/util");
|
||||||
|
|
||||||
exports.version = require("../package.json").version;
|
exports.version = require("../package.json").version;
|
||||||
exports.latestVersion = null;
|
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;
|
let interval;
|
||||||
|
|
||||||
/** Start 48 hour check interval */
|
|
||||||
exports.startInterval = () => {
|
exports.startInterval = () => {
|
||||||
let check = async () => {
|
let check = async () => {
|
||||||
|
if (await setting("checkUpdate") === false) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.debug("update-checker", "Retrieving latest versions");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await axios.get("https://uptime.kuma.pet/version");
|
const res = await axios.get(UPDATE_CHECKER_LATEST_VERSION_URL);
|
||||||
|
|
||||||
// For debug
|
// For debug
|
||||||
if (process.env.TEST_CHECK_VERSION === "1") {
|
if (process.env.TEST_CHECK_VERSION === "1") {
|
||||||
res.data.slow = "1000.0.0";
|
res.data.slow = "1000.0.0";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (await setting("checkUpdate") === false) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let checkBeta = await setting("checkBeta");
|
let checkBeta = await setting("checkBeta");
|
||||||
|
|
||||||
if (checkBeta && res.data.beta) {
|
if (checkBeta && res.data.beta) {
|
||||||
|
@ -35,12 +41,14 @@ exports.startInterval = () => {
|
||||||
exports.latestVersion = res.data.slow;
|
exports.latestVersion = res.data.slow;
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (_) { }
|
} catch (_) {
|
||||||
|
log.info("update-checker", "Failed to check for new versions");
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
check();
|
check();
|
||||||
interval = setInterval(check, 3600 * 1000 * 48);
|
interval = setInterval(check, UPDATE_CHECKER_INTERVAL_MS);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue