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

68 lines
1.8 KiB
JavaScript
Raw Normal View History

2015-09-17 16:25:15 -04:00
'use strict';
var async = require('async');
var nconf = require('nconf');
2015-09-17 16:25:15 -04:00
var plugins = require('../../plugins');
var meta = require('../../meta');
2015-09-17 16:25:15 -04:00
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;
});
2018-02-21 12:52:26 -05:00
var installedPlugins = payload.compatible.filter(function (plugin) {
return plugin && plugin.installed;
});
var activePlugins = payload.all.filter(function (plugin) {
return plugin && plugin.installed && plugin.active;
});
2015-09-17 16:25:15 -04:00
2017-06-22 19:03:49 -04:00
res.render('admin/extend/plugins', {
2018-02-21 12:52:26 -05:00
installed: installedPlugins,
installedCount: installedPlugins.length,
activeCount: activePlugins.length,
inactiveCount: Math.max(0, installedPlugins.length - activePlugins.length),
2017-06-22 19:03:49 -04:00
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.includes(plugin.name);
2017-06-22 19:03:49 -04:00
}),
submitPluginUsage: meta.config.submitPluginUsage,
version: nconf.get('version'),
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
};