2022-03-07 10:24:24 +02:00
|
|
|
const { setSetting, setting } = require("./util-server");
|
2021-08-21 13:50:22 +02:00
|
|
|
const axios = require("axios");
|
2022-03-07 10:24:24 +02:00
|
|
|
const compareVersions = require("compare-versions");
|
2021-08-21 13:50:22 +02:00
|
|
|
|
|
|
|
exports.version = require("../package.json").version;
|
|
|
|
exports.latestVersion = null;
|
|
|
|
|
|
|
|
let interval;
|
|
|
|
|
|
|
|
exports.startInterval = () => {
|
|
|
|
let check = async () => {
|
|
|
|
try {
|
2021-10-30 18:36:46 +02:00
|
|
|
const res = await axios.get("https://uptime.kuma.pet/version");
|
2021-08-21 13:50:22 +02:00
|
|
|
|
|
|
|
// For debug
|
|
|
|
if (process.env.TEST_CHECK_VERSION === "1") {
|
2021-10-30 18:36:46 +02:00
|
|
|
res.data.slow = "1000.0.0";
|
|
|
|
}
|
|
|
|
|
2022-04-05 13:43:23 +02:00
|
|
|
if (await setting("checkUpdate") === false) {
|
2022-03-07 10:24:24 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let checkBeta = await setting("checkBeta");
|
|
|
|
|
|
|
|
if (checkBeta && res.data.beta) {
|
|
|
|
if (compareVersions.compare(res.data.beta, res.data.beta, ">")) {
|
|
|
|
exports.latestVersion = res.data.beta;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-30 18:36:46 +02:00
|
|
|
if (res.data.slow) {
|
|
|
|
exports.latestVersion = res.data.slow;
|
2021-08-21 13:50:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} catch (_) { }
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
check();
|
2021-08-22 08:07:56 +02:00
|
|
|
interval = setInterval(check, 3600 * 1000 * 48);
|
2021-08-21 13:50:22 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.enableCheckUpdate = async (value) => {
|
|
|
|
await setSetting("checkUpdate", value);
|
|
|
|
|
|
|
|
clearInterval(interval);
|
|
|
|
|
|
|
|
if (value) {
|
|
|
|
exports.startInterval();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.socket = null;
|