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(),
|
2020-09-28 19:53: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);
|
2023-04-15 01:17:11 +02:00
|
|
|
const installedPlugins = compatible.filter(plugin => plugin && (plugin.installed || (nconf.get('plugins:active') && plugin.active)));
|
|
|
|
|
const activePlugins = all.filter(plugin => plugin && (plugin.installed || nconf.get('plugins:active')) && plugin.active);
|
2024-09-30 10:27:03 -04:00
|
|
|
const inactivePlugins = all.filter(plugin => plugin && (plugin.installed || nconf.get('plugins:active')) && !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
|
|
|
|
2024-09-30 10:27:03 -04:00
|
|
|
const upgrade = compatible.filter(p => p.installed && p.outdated);
|
2019-08-14 16:27:58 -04:00
|
|
|
res.render('admin/extend/plugins', {
|
|
|
|
|
installed: installedPlugins,
|
|
|
|
|
installedCount: installedPlugins.length,
|
2024-09-30 10:27:03 -04:00
|
|
|
active: activePlugins,
|
2019-08-14 16:27:58 -04:00
|
|
|
activeCount: activePlugins.length,
|
2024-09-30 10:27:03 -04:00
|
|
|
inactive: inactivePlugins,
|
|
|
|
|
inactiveCount: inactivePlugins.length,
|
2022-07-25 20:04:55 +02:00
|
|
|
canChangeState: !nconf.get('plugins:active'),
|
2024-09-30 10:27:03 -04:00
|
|
|
upgrade: upgrade,
|
|
|
|
|
upgradeCount: upgrade.length,
|
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'),
|
2024-12-11 11:21:58 -05:00
|
|
|
isStarterPlan: nconf.get('saas_plan') === 'starter',
|
2019-08-14 16:27:58 -04:00
|
|
|
});
|
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 [];
|
|
|
|
|
}
|
|
|
|
|
}
|