mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-05-08 16:05:05 -04:00
Cache etherpad informations for one hour
This commit is contained in:
parent
94ad1a594d
commit
43a7f53ddc
1 changed files with 13 additions and 3 deletions
|
@ -5,10 +5,17 @@ const axios = require('axios');
|
|||
const headers = {
|
||||
'User-Agent': 'Etherpad ' + settings.getEpVersion(),
|
||||
}
|
||||
let infos;
|
||||
|
||||
const loadEtherpadInformations = () =>
|
||||
axios.get('https://static.etherpad.org/info.json', {headers: headers})
|
||||
const updateInterval = 60 * 60 * 1000; // 1 hour
|
||||
let infos;
|
||||
let lastLoadingTime = null;
|
||||
|
||||
const loadEtherpadInformations = () => {
|
||||
if (lastLoadingTime !== null && Date.now() - lastLoadingTime < updateInterval) {
|
||||
return Promise.resolve(infos);
|
||||
}
|
||||
|
||||
return axios.get('https://static.etherpad.org/info.json', {headers: headers})
|
||||
.then(async resp => {
|
||||
try {
|
||||
infos = await resp.data;
|
||||
|
@ -16,11 +23,14 @@ const loadEtherpadInformations = () =>
|
|||
await Promise.reject("Could not retrieve current version")
|
||||
return
|
||||
}
|
||||
|
||||
lastLoadingTime = Date.now();
|
||||
return await Promise.resolve(infos);
|
||||
} catch (err) {
|
||||
return await Promise.reject(err);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
exports.getLatestVersion = () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue