From 8d2be0ed7bb87283a1ec98609df6b82d83db706a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 11 Jul 2019 17:23:24 +0200 Subject: WIP plugins: move plugin CLI in peertube script Install/uninstall/list plugins remotely --- server/controllers/api/plugins.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'server/controllers/api') diff --git a/server/controllers/api/plugins.ts b/server/controllers/api/plugins.ts index f17e8cab9..8e59f27cf 100644 --- a/server/controllers/api/plugins.ts +++ b/server/controllers/api/plugins.ts @@ -21,6 +21,7 @@ import { import { PluginManager } from '../../lib/plugins/plugin-manager' import { InstallPlugin } from '../../../shared/models/plugins/install-plugin.model' import { ManagePlugin } from '../../../shared/models/plugins/manage-plugin.model' +import { logger } from '../../helpers/logger' const pluginRouter = express.Router() @@ -46,7 +47,7 @@ pluginRouter.get('/:npmName/registered-settings', authenticate, ensureUserHasRight(UserRight.MANAGE_PLUGINS), asyncMiddleware(existingPluginValidator), - asyncMiddleware(getPluginRegisteredSettings) + getPluginRegisteredSettings ) pluginRouter.put('/:npmName/settings', @@ -101,7 +102,14 @@ function getPlugin (req: express.Request, res: express.Response) { async function installPlugin (req: express.Request, res: express.Response) { const body: InstallPlugin = req.body - await PluginManager.Instance.install(body.npmName) + const fromDisk = !!body.path + const toInstall = body.npmName || body.path + try { + await PluginManager.Instance.install(toInstall, undefined, fromDisk) + } catch (err) { + logger.warn('Cannot install plugin %s.', toInstall, { err }) + return res.sendStatus(400) + } return res.sendStatus(204) } @@ -114,10 +122,10 @@ async function uninstallPlugin (req: express.Request, res: express.Response) { return res.sendStatus(204) } -async function getPluginRegisteredSettings (req: express.Request, res: express.Response) { +function getPluginRegisteredSettings (req: express.Request, res: express.Response) { const plugin = res.locals.plugin - const settings = await PluginManager.Instance.getSettings(plugin.name) + const settings = PluginManager.Instance.getSettings(plugin.name) return res.json({ settings -- cgit v1.2.3