lint: src/node/utils/UpdateCheck.js

This commit is contained in:
John McLear 2021-01-21 21:06:52 +00:00 committed by Richard Hansen
parent f8323eae89
commit 02c1bf7d81

View file

@ -1,30 +1,29 @@
'use strict';
const semver = require('semver'); const semver = require('semver');
const settings = require('./Settings'); const settings = require('./Settings');
const request = require('request'); const request = require('request');
let infos; let infos;
function loadEtherpadInformations() { const loadEtherpadInformations = () => new Promise((resolve, reject) => {
return new Promise((resolve, reject) => { request('https://static.etherpad.org/info.json', (er, response, body) => {
request('https://static.etherpad.org/info.json', (er, response, body) => { if (er) return reject(er);
if (er) return reject(er);
try { try {
infos = JSON.parse(body); infos = JSON.parse(body);
return resolve(infos); return resolve(infos);
} catch (err) { } catch (err) {
return reject(err); return reject(err);
} }
});
}); });
} });
exports.getLatestVersion = function () { exports.getLatestVersion = () => {
exports.needsUpdate(); exports.needsUpdate();
return infos.latestVersion; return infos.latestVersion;
}; };
exports.needsUpdate = function (cb) { exports.needsUpdate = (cb) => {
loadEtherpadInformations().then((info) => { loadEtherpadInformations().then((info) => {
if (semver.gt(info.latestVersion, settings.getEpVersion())) { if (semver.gt(info.latestVersion, settings.getEpVersion())) {
if (cb) return cb(true); if (cb) return cb(true);
@ -35,7 +34,7 @@ exports.needsUpdate = function (cb) {
}); });
}; };
exports.check = function () { exports.check = () => {
exports.needsUpdate((needsUpdate) => { exports.needsUpdate((needsUpdate) => {
if (needsUpdate) { if (needsUpdate) {
console.warn(`Update available: Download the actual version ${infos.latestVersion}`); console.warn(`Update available: Download the actual version ${infos.latestVersion}`);