Files
NodeBB/src/controllers/admin/plugins.js

57 lines
1.3 KiB
JavaScript
Raw Normal View History

2015-09-17 16:25:15 -04:00
'use strict';
var async = require('async');
var plugins = require('../../plugins');
2017-06-22 19:03:49 -04:00
var pluginsController = module.exports;
2015-09-17 16:25:15 -04:00
pluginsController.get = function (req, res, next) {
2017-06-22 19:03:49 -04:00
async.waterfall([
function (next) {
async.parallel({
compatible: function (next) {
plugins.list(function (err, plugins) {
if (err || !Array.isArray(plugins)) {
plugins = [];
}
2015-09-17 16:25:15 -04:00
2017-06-22 19:03:49 -04:00
next(null, plugins);
});
},
all: function (next) {
plugins.list(false, function (err, plugins) {
if (err || !Array.isArray(plugins)) {
plugins = [];
}
next(null, plugins);
});
},
}, next);
2015-09-17 16:25:15 -04:00
},
2017-06-22 19:03:49 -04:00
function (payload) {
var compatiblePkgNames = payload.compatible.map(function (pkgData) {
return pkgData.name;
});
2015-09-17 16:25:15 -04:00
2017-06-22 19:03:49 -04:00
res.render('admin/extend/plugins', {
installed: payload.compatible.filter(function (plugin) {
return plugin.installed;
}),
upgradeCount: payload.compatible.reduce(function (count, current) {
if (current.installed && current.outdated) {
count += 1;
}
return count;
}, 0),
download: payload.compatible.filter(function (plugin) {
return !plugin.installed;
}),
incompatible: payload.all.filter(function (plugin) {
return compatiblePkgNames.indexOf(plugin.name) === -1;
}),
2015-09-17 16:25:15 -04:00
});
2017-02-17 19:31:21 -07:00
},
2017-06-22 19:03:49 -04:00
], next);
2015-09-17 16:25:15 -04:00
};