2015-09-17 16:25:15 -04:00
|
|
|
'use strict';
|
|
|
|
|
|
2019-08-14 16:27:58 -04:00
|
|
|
const nconf = require('nconf');
|
|
|
|
|
const winston = require('winston');
|
|
|
|
|
const plugins = require('../../plugins');
|
|
|
|
|
const meta = require('../../meta');
|
2015-09-17 16:25:15 -04:00
|
|
|
|
2019-08-14 16:27:58 -04:00
|
|
|
const pluginsController = module.exports;
|
2015-09-17 16:25:15 -04:00
|
|
|
|
2019-08-14 16:27:58 -04:00
|
|
|
pluginsController.get = async function (req, res) {
|
2020-09-28 19:53:47 -04:00
|
|
|
const [compatible, all, trending] = await Promise.all([
|
2020-09-28 16:20:41 -04:00
|
|
|
getCompatiblePlugins(),
|
2019-08-14 16:27:58 -04:00
|
|
|
getAllPlugins(),
|
2022-09-04 12:00:27 -04:00
|
|
|
Promise.resolve([]),
|
2022-09-04 12:28:47 -04:00
|
|
|
// plugins.listTrending(),
|
2019-08-14 16:27:58 -04:00
|
|
|
]);
|
2015-09-17 16:25:15 -04:00
|
|
|
|
2019-08-14 16:27:58 -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
|
|
|
|
2020-09-28 19:53:47 -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;
|
|
|
|
|
});
|
2020-09-28 19:53:47 -04:00
|
|
|
|
2019-08-14 16:27:58 -04:00
|
|
|
res.render('admin/extend/plugins', {
|
|
|
|
|
installed: installedPlugins,
|
|
|
|
|
installedCount: installedPlugins.length,
|
|
|
|
|
activeCount: activePlugins.length,
|
|
|
|
|
inactiveCount: Math.max(0, installedPlugins.length - activePlugins.length),
|
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) => {
|
2019-08-14 16:27:58 -04:00
|
|
|
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)),
|
2020-09-28 19:53:47 -04:00
|
|
|
trending: trendingPlugins,
|
2019-08-14 16:27:58 -04:00
|
|
|
submitPluginUsage: meta.config.submitPluginUsage,
|
|
|
|
|
version: nconf.get('version'),
|
|
|
|
|
});
|
2015-09-17 16:25:15 -04:00
|
|
|
};
|
2019-08-14 16:27:58 -04:00
|
|
|
|
2020-09-28 16:20:41 -04:00
|
|
|
async function getCompatiblePlugins() {
|
2019-08-14 16:27:58 -04:00
|
|
|
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) {
|
2020-06-20 23:32:12 -04:00
|
|
|
winston.error(err.stack);
|
2019-08-14 16:27:58 -04:00
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
}
|