From 6702a1b2ccd666285dee9c72b5bace641d2fce8b Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 16 Jul 2019 11:33:22 +0200 Subject: Add ability to search available plugins --- server/controllers/api/plugins.ts | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'server/controllers') diff --git a/server/controllers/api/plugins.ts b/server/controllers/api/plugins.ts index 14675fdf3..114cc49b6 100644 --- a/server/controllers/api/plugins.ts +++ b/server/controllers/api/plugins.ts @@ -8,12 +8,13 @@ import { setDefaultPagination, setDefaultSort } from '../../middlewares' -import { pluginsSortValidator } from '../../middlewares/validators' +import { availablePluginsSortValidator, pluginsSortValidator } from '../../middlewares/validators' import { PluginModel } from '../../models/server/plugin' import { UserRight } from '../../../shared/models/users' import { existingPluginValidator, installOrUpdatePluginValidator, + listAvailablePluginsValidator, listPluginsValidator, uninstallPluginValidator, updatePluginSettingsValidator @@ -22,9 +23,22 @@ import { PluginManager } from '../../lib/plugins/plugin-manager' import { InstallOrUpdatePlugin } from '../../../shared/models/plugins/install-plugin.model' import { ManagePlugin } from '../../../shared/models/plugins/manage-plugin.model' import { logger } from '../../helpers/logger' +import { listAvailablePluginsFromIndex } from '../../lib/plugins/plugin-index' +import { PeertubePluginIndexList } from '../../../shared/models/plugins/peertube-plugin-index-list.model' const pluginRouter = express.Router() +pluginRouter.get('/available', + authenticate, + ensureUserHasRight(UserRight.MANAGE_PLUGINS), + listAvailablePluginsValidator, + paginationValidator, + availablePluginsSortValidator, + setDefaultSort, + setDefaultPagination, + asyncMiddleware(listAvailablePlugins) +) + pluginRouter.get('/', authenticate, ensureUserHasRight(UserRight.MANAGE_PLUGINS), @@ -88,10 +102,10 @@ export { // --------------------------------------------------------------------------- async function listPlugins (req: express.Request, res: express.Response) { - const type = req.query.type + const pluginType = req.query.pluginType const resultList = await PluginModel.listForApi({ - type, + pluginType, start: req.query.start, count: req.query.count, sort: req.query.sort @@ -160,3 +174,11 @@ async function updatePluginSettings (req: express.Request, res: express.Response return res.sendStatus(204) } + +async function listAvailablePlugins (req: express.Request, res: express.Response) { + const query: PeertubePluginIndexList = req.query + + const resultList = await listAvailablePluginsFromIndex(query) + + return res.json(resultList) +} -- cgit v1.2.3