mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-05-08 08:01:02 -04:00

* Fixed determining file extension. * Added ts-node * Fixed backend tests. * Fixed frontend test runs. * Fixed tests. * Use script approach for starting etherpad. * Change directory to src. * Fixed env. * Change directory * Fixed build arg. * Fixed docker build. * Fixed. * Fixed cypress file path. * Fixed. * Use latest node container. * Fixed windows workflow. * Use tsx and optimized docker image. * Added workflow for type checks. * Fixed. * Added tsconfig. * Converted more files to typescript. * Removed commented keys. * Typed caching middleware. * Added script for checking the types. * Moved SecretRotator to typescript. * Fixed npm installation and moved to types folder. * Use better scripts for watching typescript changes. * Update windows.yml * Fixed order of npm installation. * Converted i18n. * Added more types. * Added more types. * Fixed import. * Fixed tests. * Fixed tests. * Fixed type checking test. * Fixed stats * Added express types. * fixed.
63 lines
1.6 KiB
TypeScript
63 lines
1.6 KiB
TypeScript
'use strict';
|
|
const semver = require('semver');
|
|
const settings = require('./Settings');
|
|
const axios = require('axios');
|
|
const headers = {
|
|
'User-Agent': 'Etherpad/' + settings.getEpVersion(),
|
|
}
|
|
|
|
type Infos = {
|
|
latestVersion: string
|
|
}
|
|
|
|
|
|
const updateInterval = 60 * 60 * 1000; // 1 hour
|
|
let infos: Infos;
|
|
let lastLoadingTime: number | null = 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: any) => {
|
|
infos = await resp.data;
|
|
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: Error) => {
|
|
return await Promise.reject(err);
|
|
});
|
|
}
|
|
|
|
|
|
exports.getLatestVersion = () => {
|
|
exports.needsUpdate().catch();
|
|
return infos?.latestVersion;
|
|
};
|
|
|
|
exports.needsUpdate = async (cb: Function) => {
|
|
await loadEtherpadInformations()
|
|
.then((info:Infos) => {
|
|
if (semver.gt(info.latestVersion, settings.getEpVersion())) {
|
|
if (cb) return cb(true);
|
|
}
|
|
}).catch((err: Error) => {
|
|
console.error(`Can not perform Etherpad update check: ${err}`);
|
|
if (cb) return cb(false);
|
|
});
|
|
};
|
|
|
|
exports.check = () => {
|
|
exports.needsUpdate((needsUpdate: boolean) => {
|
|
if (needsUpdate) {
|
|
console.warn(`Update available: Download the actual version ${infos.latestVersion}`);
|
|
}
|
|
});
|
|
};
|