2021-08-21 04:50:22 -07: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 {
|
2021-10-30 09:36:46 -07:00
|
|
|
const res = await axios.get("https://uptime.kuma.pet/version");
|
2021-08-21 04:50:22 -07:00
|
|
|
|
|
|
|
// For debug
|
|
|
|
if (process.env.TEST_CHECK_VERSION === "1") {
|
2021-10-30 09:36:46 -07:00
|
|
|
res.data.slow = "1000.0.0";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (res.data.slow) {
|
|
|
|
exports.latestVersion = res.data.slow;
|
2021-08-21 04:50:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
} catch (_) { }
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
check();
|
2021-08-21 23:07:56 -07:00
|
|
|
interval = setInterval(check, 3600 * 1000 * 48);
|
2021-08-21 04:50:22 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.enableCheckUpdate = async (value) => {
|
|
|
|
await setSetting("checkUpdate", value);
|
|
|
|
|
|
|
|
clearInterval(interval);
|
|
|
|
|
|
|
|
if (value) {
|
|
|
|
exports.startInterval();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.socket = null;
|