mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-01-19 14:13:34 +01:00
lint: src/node/utils/UpdateCheck.js
This commit is contained in:
parent
f8323eae89
commit
02c1bf7d81
1 changed files with 14 additions and 15 deletions
|
@ -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}`);
|
||||||
|
|
Loading…
Reference in a new issue