Proxy for Plugins fix (#7655)
stephannn committed
Feb 27, 2026 at 17:29 UTC
b93d144b31d50c68abbf60ffcb30e7155f159cd6
1 file changed
+14
-13
pluginHandler.js
+14
-13
@@ -252,9 +252,8 @@ module.exports.pluginHandler = function (parent) {
252
var http = (configUrl.indexOf('https://') >= 0) ? require('https') : require('http');
253
if (configUrl.indexOf('://') === -1) reject("Unable to fetch the config: Bad URL (" + configUrl + ")");
254
var options = require('url').parse(configUrl);
255
- if (typeof parent.config.settings.plugins.proxy == 'string') { // Proxy support
256
- const HttpsProxyAgent = require('https-proxy-agent');
257
- options.agent = new HttpsProxyAgent(require('url').parse(parent.config.settings.plugins.proxy));
255
+ if (typeof parent.config.settings.plugins.proxy == 'string' || process.env['HTTP_PROXY'] || process.env['HTTPS_PROXY'] || process.env['http_proxy'] || process.env['https_proxy']) { // Proxy support
256
+ options.agent = new (require('https-proxy-agent').HttpsProxyAgent)(require('url').parse(parent.config.settings.plugins.proxy) || process.env['HTTP_PROXY'] || process.env['HTTPS_PROXY'] || process.env['http_proxy'] || process.env['https_proxy']);
257
}
258
http.get(options, function (res) {
259
var configStr = '';
@@ -276,7 +275,6 @@ module.exports.pluginHandler = function (parent) {
275
reject("Error getting plugin config. Check that you have valid JSON.");
276
}
277
});
279
-
278
}).on('error', function (e) {
279
reject("Error getting plugin config: " + e.message);
280
});
@@ -437,16 +435,17 @@ module.exports.pluginHandler = function (parent) {
435
followRedirects: true,
436
method: 'GET'
437
};
440
- if (typeof parent.config.settings.plugins.proxy == 'string') { // Proxy support
441
- const HttpsProxyAgent = require('https-proxy-agent');
442
- opts.agent = new HttpsProxyAgent(require('url').parse(parent.config.settings.plugins.proxy));
438
+ if (typeof parent.config.settings.plugins.proxy == 'string' || process.env['HTTP_PROXY'] || process.env['HTTPS_PROXY'] || process.env['http_proxy'] || process.env['https_proxy']) { // Proxy support
439
+ opts.agent = new (require('https-proxy-agent').HttpsProxyAgent)(require('url').parse(parent.config.settings.plugins.proxy) || process.env['HTTP_PROXY'] || process.env['HTTPS_PROXY'] || process.env['http_proxy'] || process.env['https_proxy']);
440
}
441
+ var done = false;
442
var request = http.get(opts, function (response) {
443
// handle redirections with grace
444
if (response.headers.location) {
445
file.close(() => obj.fs.unlink(fileName, () => {}));
446
return obj.installPlugin(id, version_only, response.headers.location, func);
447
}
448
+ if ((response.statusCode != null) && (response.statusCode >= 400)) { return console.log('Error downloading plugin: HTTP ' + response.statusCode); }
449
response.pipe(file);
450
file.on('finish', function () {
451
file.close(function () {
@@ -486,11 +485,11 @@ module.exports.pluginHandler = function (parent) {
485
});
486
zipfile.on('end', function () {
487
setTimeout(function () {
489
- obj.fs.unlinkSync(fileName);
488
+ try { obj.fs.unlinkSync(fileName); } catch (ex) { }
489
if (version_only == null || version_only === false) {
491
- parent.db.setPluginStatus(id, 1, func);
490
+ parent.db.setPluginStatus(id, 1, function () { if (done) return; done = true; if (typeof func == 'function') { func(null); } });
491
} else {
493
- parent.db.updatePlugin(id, { status: 1, version: version_only.name }, func);
492
+ parent.db.updatePlugin(id, { status: 1, version: version_only.name }, function () { if (done) return; done = true; if (typeof func == 'function') { func(null); } });
493
}
494
try {
495
obj.plugins[plugin.shortName] = require(obj.pluginPath + '/' + plugin.shortName + '/' + plugin.shortName + '.js')[plugin.shortName](obj);
@@ -505,10 +504,13 @@ module.exports.pluginHandler = function (parent) {
504
parent.updateMeshCore();
505
});
506
});
507
+ zipfile.on('error', function (e) { console.log('Error extracting plugin ZIP: ' + e.message); });
508
});
509
});
510
});
511
});
512
+ request.on('error', function (e) { console.log('Error downloading plugin: ' + e.message); });
513
+ request.setTimeout(30000, function () { request.destroy(new Error('Timed out while downloading plugin')); });
514
} else if (plugin.repository.type == 'npm') {
515
// @TODO npm support? (need a test plugin)
516
}
@@ -532,9 +534,8 @@ module.exports.pluginHandler = function (parent) {
534
'Accept': 'application/vnd.github.v3+json'
535
}
536
};
535
- if (typeof parent.config.settings.plugins.proxy == 'string') { // Proxy support
536
- const HttpsProxyAgent = require('https-proxy-agent');
537
- options.agent = new HttpsProxyAgent(require('url').parse(parent.config.settings.plugins.proxy));
537
+ if (typeof parent.config.settings.plugins.proxy == 'string' || process.env['HTTP_PROXY'] || process.env['HTTPS_PROXY'] || process.env['http_proxy'] || process.env['https_proxy']) { // Proxy support
538
+ options.agent = new (require('https-proxy-agent').HttpsProxyAgent)(require('url').parse(parent.config.settings.plugins.proxy) || process.env['HTTP_PROXY'] || process.env['HTTPS_PROXY'] || process.env['http_proxy'] || process.env['https_proxy']);
539
}
540
http.get(opts, function (res) {
541
var versStr = '';