mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-22 08:26:16 -04:00
Feature/axios (#5776)
* Move from deprecated request package to axios.
* Fixed package.json
* Another check.
* Fixing npm - hopefully the last.
* Remove double parsing of JSON.
* Bump bundled npm to also get rid of request in the bundled npm.
* Revert "Bump bundled npm to also get rid of request in the bundled npm."
This reverts commit b60fa4f435
.
This commit is contained in:
parent
7748e8d113
commit
049231e4af
6 changed files with 311 additions and 435 deletions
|
@ -1,30 +1,34 @@
|
|||
'use strict';
|
||||
const semver = require('semver');
|
||||
const settings = require('./Settings');
|
||||
const request = require('request');
|
||||
|
||||
const axios = require('axios');
|
||||
let infos;
|
||||
|
||||
const loadEtherpadInformations = () => new Promise((resolve, reject) => {
|
||||
request('https://static.etherpad.org/info.json', (er, response, body) => {
|
||||
if (er) return reject(er);
|
||||
const loadEtherpadInformations = () =>
|
||||
axios.get('https://static.etherpad.org/info.json')
|
||||
.then(async resp => {
|
||||
try {
|
||||
infos = await resp.data;
|
||||
if (infos === undefined || infos === null) {
|
||||
await Promise.reject("Could not retrieve current version")
|
||||
return
|
||||
}
|
||||
return await Promise.resolve(infos);
|
||||
}
|
||||
catch (err) {
|
||||
return await Promise.reject(err);
|
||||
}
|
||||
})
|
||||
|
||||
try {
|
||||
infos = JSON.parse(body);
|
||||
return resolve(infos);
|
||||
} catch (err) {
|
||||
return reject(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
exports.getLatestVersion = () => {
|
||||
exports.needsUpdate();
|
||||
return infos.latestVersion;
|
||||
};
|
||||
|
||||
exports.needsUpdate = (cb) => {
|
||||
loadEtherpadInformations().then((info) => {
|
||||
exports.needsUpdate = async (cb) => {
|
||||
await loadEtherpadInformations()
|
||||
.then((info) => {
|
||||
if (semver.gt(info.latestVersion, settings.getEpVersion())) {
|
||||
if (cb) return cb(true);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue