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

@ -3,9 +3,9 @@
const log4js = require('log4js');
const plugins = require('./plugins');
const hooks = require('./hooks');
const request = require('request');
const runCmd = require('../../../node/utils/run_cmd');
const settings = require('../../../node/utils/Settings');
const axios = require('axios');
const logger = log4js.getLogger('plugins');
@ -71,28 +71,20 @@ let cacheTimestamp = 0;
exports.getAvailablePlugins = (maxCacheAge) => {
const nowTimestamp = Math.round(Date.now() / 1000);
return new Promise((resolve, reject) => {
// check cache age before making any request
if (exports.availablePlugins && maxCacheAge && (nowTimestamp - cacheTimestamp) <= maxCacheAge) {
return resolve(exports.availablePlugins);
}
request('https://static.etherpad.org/plugins.json', (er, response, plugins) => {
if (er) return reject(er);
try {
plugins = JSON.parse(plugins);
} catch (err) {
logger.error(`error parsing plugins.json: ${err.stack || err}`);
plugins = [];
return new Promise(async (resolve, reject) => {
// check cache age before making any request
if (exports.availablePlugins && maxCacheAge && (nowTimestamp - cacheTimestamp) <= maxCacheAge) {
return resolve(exports.availablePlugins);
}
exports.availablePlugins = plugins;
cacheTimestamp = nowTimestamp;
resolve(plugins);
});
});
};
await axios.get('https://static.etherpad.org/plugins.json')
.then(pluginsLoaded => {
exports.availablePlugins = pluginsLoaded.data;
cacheTimestamp = nowTimestamp;
resolve(exports.availablePlugins);
})
})
}
exports.search = (searchTerm, maxCacheAge) => exports.getAvailablePlugins(maxCacheAge).then(