Improve update check (#5945)
* Send etherpad version in update check request * Cache etherpad informations for one hour * Change format of User-Agent * Improve exception handlingpull/5946/head
parent
f2faa3fa84
commit
f9a3a6aaae
|
@ -2,28 +2,39 @@
|
||||||
const semver = require('semver');
|
const semver = require('semver');
|
||||||
const settings = require('./Settings');
|
const settings = require('./Settings');
|
||||||
const axios = require('axios');
|
const axios = require('axios');
|
||||||
let infos;
|
const headers = {
|
||||||
|
'User-Agent': 'Etherpad/' + settings.getEpVersion(),
|
||||||
|
}
|
||||||
|
|
||||||
const loadEtherpadInformations = () =>
|
const updateInterval = 60 * 60 * 1000; // 1 hour
|
||||||
axios.get('https://static.etherpad.org/info.json')
|
let infos;
|
||||||
.then(async resp => {
|
let lastLoadingTime = null;
|
||||||
try {
|
|
||||||
infos = await resp.data;
|
const loadEtherpadInformations = () => {
|
||||||
if (infos === undefined || infos === null) {
|
if (lastLoadingTime !== null && Date.now() - lastLoadingTime < updateInterval) {
|
||||||
await Promise.reject("Could not retrieve current version")
|
return Promise.resolve(infos);
|
||||||
return
|
}
|
||||||
}
|
|
||||||
return await Promise.resolve(infos);
|
return axios.get('https://static.etherpad.org/info.json', {headers: headers})
|
||||||
}
|
.then(async resp => {
|
||||||
catch (err) {
|
infos = await resp.data;
|
||||||
return await Promise.reject(err);
|
if (infos === undefined || infos === null) {
|
||||||
}
|
await Promise.reject("Could not retrieve current version")
|
||||||
})
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
lastLoadingTime = Date.now();
|
||||||
|
return await Promise.resolve(infos);
|
||||||
|
})
|
||||||
|
.catch(async err => {
|
||||||
|
return await Promise.reject(err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
exports.getLatestVersion = () => {
|
exports.getLatestVersion = () => {
|
||||||
exports.needsUpdate();
|
exports.needsUpdate().catch();
|
||||||
return infos.latestVersion;
|
return infos?.latestVersion;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.needsUpdate = async (cb) => {
|
exports.needsUpdate = async (cb) => {
|
||||||
|
|
Loading…
Reference in New Issue