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

71 lines
2.0 KiB
JavaScript
Raw Normal View History

2015-09-17 16:25:15 -04:00
'use strict';
const nconf = require('nconf');
const winston = require('winston');
const plugins = require('../../plugins');
const meta = require('../../meta');
2015-09-17 16:25:15 -04:00
const pluginsController = module.exports;
2015-09-17 16:25:15 -04:00
pluginsController.get = async function (req, res) {
const [compatible, all, trending] = await Promise.all([
2020-09-28 16:20:41 -04:00
getCompatiblePlugins(),
getAllPlugins(),
Promise.resolve([]),
2022-09-04 12:28:47 -04:00
// plugins.listTrending(),
]);
2015-09-17 16:25:15 -04:00
const compatiblePkgNames = compatible.map(pkgData => pkgData.name);
const installedPlugins = compatible.filter(plugin => plugin && plugin.installed);
const activePlugins = all.filter(plugin => plugin && plugin.installed && plugin.active);
2017-06-22 19:03:49 -04:00
const trendingScores = trending.reduce((memo, cur) => {
memo[cur.label] = cur.value;
return memo;
}, {});
2021-02-04 02:07:29 -07:00
const trendingPlugins = all
.filter(plugin => plugin && Object.keys(trendingScores).includes(plugin.id))
.sort((a, b) => trendingScores[b.id] - trendingScores[a.id])
.map((plugin) => {
plugin.downloads = trendingScores[plugin.id];
return plugin;
});
res.render('admin/extend/plugins', {
installed: installedPlugins,
installedCount: installedPlugins.length,
activeCount: activePlugins.length,
inactiveCount: Math.max(0, installedPlugins.length - activePlugins.length),
feat: Allow defining active plugins in config (#10767) * Revert "Revert "feat: cross origin opener policy options (#10710)"" This reverts commit 46050ace1a65430fe1b567086727da22afab4f73. * Revert "Revert "chore(i18n): fallback strings for new resources: nodebb.admin-settings-advanced"" This reverts commit 9f291c07d3423a41550b38770620a998b45e5c55. * feat: closes #10719, don't trim children if category is marked section * feat: fire hook to allow plugins to filter the pids returned in a user profile /cc julianlam/nodebb-plugin-support-forum#14 * fix: use `user.hidePrivateData();` more consistently across user retrieval endpoints * feat: Allow defining active plugins in config resolves #10766 * fix: assign the db result to files properly * test: add tests with plugins in config * feat: better theme change handling * feat: add visual indication that plugins can't be activated * test: correct hooks * test: fix test definitions * test: remove instead of resetting nconf to avoid affecting other tests * test: ... I forgot how nconf worked * fix: remove negation * docs: improve wording of error message * feat: reduce code duplication * style: remove a redundant space * fix: remove unused imports * fix: use nconf instead of requiring config.json * fix: await... * fix: second missed await * fix: move back from getActiveIds to getActive * fix: use paths again? * fix: typo * fix: move require into the function * fix: forgot to change back to getActive * test: getActive returns only id * test: accedently commented out some stuff * feat: added note to top of plugins page if \!canChangeState Co-authored-by: Julian Lam <julian@nodebb.org> Co-authored-by: Barış Soner Uşaklı <barisusakli@gmail.com>
2022-07-25 20:04:55 +02:00
canChangeState: !nconf.get('plugins:active'),
2021-02-04 00:01:39 -07:00
upgradeCount: compatible.reduce((count, current) => {
if (current.installed && current.outdated) {
count += 1;
}
return count;
}, 0),
2021-02-04 00:01:39 -07:00
download: compatible.filter(plugin => !plugin.installed),
incompatible: all.filter(plugin => !compatiblePkgNames.includes(plugin.name)),
trending: trendingPlugins,
submitPluginUsage: meta.config.submitPluginUsage,
version: nconf.get('version'),
});
2015-09-17 16:25:15 -04:00
};
2020-09-28 16:20:41 -04:00
async function getCompatiblePlugins() {
return await getPlugins(true);
}
async function getAllPlugins() {
return await getPlugins(false);
}
async function getPlugins(matching) {
try {
const pluginsData = await plugins.list(matching);
return pluginsData || [];
} catch (err) {
winston.error(err.stack);
return [];
}
}