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:
SamTV12345 2023-06-27 21:20:53 +02:00 committed by GitHub
parent 7748e8d113
commit 049231e4af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 311 additions and 435 deletions

View file

@ -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);
}