diff --git a/src/controllers/admin.js b/src/controllers/admin.js index 934881a6bd..776b6e9362 100644 --- a/src/controllers/admin.js +++ b/src/controllers/admin.js @@ -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; }) }); }); diff --git a/src/plugins.js b/src/plugins.js index 046809e76e..c5cf8a1241 100644 --- a/src/plugins.js +++ b/src/plugins.js @@ -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