Exposed package data for incompatible plugins to admin/plugins controller, #3480

ping @psychobunny
v1.18.x
Julian Lam 10 years ago
parent 902d11c6af
commit a27c8f0321

@ -269,17 +269,39 @@ adminController.postCache.get = function(req, res, next) {
};
adminController.plugins.get = function(req, res, next) {
plugins.getAll(function(err, plugins) {
if (err || !Array.isArray(plugins)) {
plugins = [];
async.parallel({
compatible: function(next) {
plugins.list(function(err, plugins) {
if (err || !Array.isArray(plugins)) {
plugins = [];
}
next(null, plugins);
});
},
all: function(next) {
plugins.list(false, function(err, plugins) {
if (err || !Array.isArray(plugins)) {
plugins = [];
}
next(null, plugins);
});
}
}, function(err, payload) {
var compatiblePkgNames = payload.compatible.map(function(pkgData) {
return pkgData.name;
});
res.render('admin/extend/plugins' , {
installed: plugins.filter(function(plugin) {
installed: payload.compatible.filter(function(plugin) {
return plugin.installed;
}),
download: plugins.filter(function(plugin) {
download: payload.compatible.filter(function(plugin) {
return !plugin.installed;
}),
incompatible: payload.all.filter(function(plugin) {
return compatiblePkgNames.indexOf(plugin.name) === -1;
})
});
});

@ -195,8 +195,13 @@ var fs = require('fs'),
});
};
Plugins.getAll = function(callback) {
var url = (nconf.get('registry') || 'https://packages.nodebb.org') + '/api/v1/plugins?version=' + require('../package.json').version;
Plugins.list = function(matching, callback) {
if (arguments.length === 1 && typeof matching === 'function') {
callback = matching;
matching = true;
}
var url = (nconf.get('registry') || 'https://packages.nodebb.org') + '/api/v1/plugins' + (matching !== false ? '?version=' + require('../package.json').version : '');
require('request')(url, {
json: true

Loading…
Cancel
Save