2021-08-21 14:50:22 +03:00
|
|
|
const { setSetting } = require("./util-server");
|
|
|
|
const axios = require("axios");
|
|
|
|
|
|
|
|
exports.version = require("../package.json").version;
|
|
|
|
exports.latestVersion = null;
|
|
|
|
|
|
|
|
let interval;
|
|
|
|
|
|
|
|
exports.startInterval = () => {
|
|
|
|
let check = async () => {
|
|
|
|
try {
|
|
|
|
const res = await axios.get("https://raw.githubusercontent.com/louislam/uptime-kuma/master/package.json");
|
|
|
|
|
|
|
|
if (typeof res.data === "string") {
|
|
|
|
res.data = JSON.parse(res.data);
|
|
|
|
}
|
|
|
|
|
|
|
|
// For debug
|
|
|
|
if (process.env.TEST_CHECK_VERSION === "1") {
|
2021-09-19 14:04:51 +03:00
|
|
|
res.data.version = "1000.0.0";
|
2021-08-21 14:50:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
exports.latestVersion = res.data.version;
|
|
|
|
} catch (_) { }
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
check();
|
2021-08-22 09:07:56 +03:00
|
|
|
interval = setInterval(check, 3600 * 1000 * 48);
|
2021-08-21 14:50:22 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.enableCheckUpdate = async (value) => {
|
|
|
|
await setSetting("checkUpdate", value);
|
|
|
|
|
|
|
|
clearInterval(interval);
|
|
|
|
|
|
|
|
if (value) {
|
|
|
|
exports.startInterval();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.socket = null;
|