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 b60fa4f435c141bca332a5b344c36204eb0cc7b4.
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

@ -42,7 +42,7 @@ log "Installing dependencies..."
cd node_modules &&
{ [ -d ep_etherpad-lite ] || ln -sf ../src ep_etherpad-lite; } &&
cd ep_etherpad-lite &&
npm ci --no-optional
npm ci --no-optional --omit=optional --include=dev --lockfile-version 1
) || exit 1
# Remove all minified data to force node creating it new

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

593
src/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -31,6 +31,7 @@
],
"dependencies": {
"async": "^3.2.4",
"axios": "^1.4.0",
"clean-css": "^5.3.2",
"cookie-parser": "^1.4.6",
"cross-spawn": "^7.0.3",
@ -52,13 +53,12 @@
"log4js": "0.6.38",
"measured-core": "^2.0.0",
"mime-types": "^2.1.35",
"npm": "^6.14.15",
"npm": "^6.14.18",
"openapi-backend": "^5.9.2",
"proxy-addr": "^2.0.7",
"rate-limiter-flexible": "^2.4.1",
"rehype": "^12.0.1",
"rehype-minify-whitespace": "^5.0.1",
"request": "2.88.2",
"resolve": "1.22.2",
"security": "1.0.0",
"semver": "^7.5.3",

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(

View File

@ -4,17 +4,16 @@
*/
const common = require('./common');
const host = `http://${settings.ip}:${settings.port}`;
const request = require('request');
const froth = require('mocha-froth');
const settings = require('../container/loadSettings').loadSettings();
const axios = require('axios');
const apiKey = common.apiKey;
const apiVersion = 1;
const testPadId = `TEST_fuzz${makeid()}`;
const endPoint = function (point, version) {
version = version || apiVersion;
return `/api/${version}/${point}?apikey=${apiKey}`;
version = version || apiVersion;
return `/api/${version}/${point}?apikey=${apiKey}`;
};
console.log('Testing against padID', testPadId);
@ -22,47 +21,47 @@ console.log(`To watch the test live visit ${host}/p/${testPadId}`);
console.log('Tests will start in 5 seconds, click the URL now!');
setTimeout(() => {
for (let i = 1; i < 1000000; i++) { // 1M runs
setTimeout(() => {
runTest(i);
}, i * 100); // 100 ms
}
for (let i = 1; i < 1000000; i++) { // 1M runs
setTimeout(async () => {
await runTest(i);
}, i * 100); // 100 ms
}
}, 5000); // wait 5 seconds
function runTest(number) {
request(`${host + endPoint('createPad')}&padID=${testPadId}`, (err, res, body) => {
const req = request.post(`${host}/p/${testPadId}/import`, (err, res, body) => {
if (err) {
async function runTest(number) {
await axios.get(`${host + endPoint('createPad')}&padID=${testPadId}`)
.then(() => {
const req = axios.post(`${host}/p/${testPadId}/import`)
.then(() => {
console.log('Success');
let fN = '/test.txt';
let cT = 'text/plain';
// To be more aggressive every other test we mess with Etherpad
// We provide a weird file name and also set a weird contentType
if (number % 2 == 0) {
fN = froth().toString();
cT = froth().toString();
}
const form = req.form();
form.append('file', froth().toString(), {
filename: fN,
contentType: cT,
});
});
})
.catch(err => {
throw new Error('FAILURE', err);
} else {
console.log('Success');
}
});
let fN = '/test.txt';
let cT = 'text/plain';
// To be more aggressive every other test we mess with Etherpad
// We provide a weird file name and also set a weird contentType
if (number % 2 == 0) {
fN = froth().toString();
cT = froth().toString();
}
const form = req.form();
form.append('file', froth().toString(), {
filename: fN,
contentType: cT,
});
});
})
}
function makeid() {
let text = '';
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let text = '';
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
for (let i = 0; i < 5; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text;
for (let i = 0; i < 5; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text;
}