aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/plugins.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-07-11 17:23:24 +0200
committerChocobozzz <chocobozzz@cpy.re>2019-07-24 10:58:16 +0200
commit8d2be0ed7bb87283a1ec98609df6b82d83db706a (patch)
tree31a36b252df32be83ceb77658a53b57f9d15e8ac /server/controllers/api/plugins.ts
parentdba85a1e9e9f603ba52e1ea42deaf3fdd799b1d8 (diff)
downloadPeerTube-8d2be0ed7bb87283a1ec98609df6b82d83db706a.tar.gz
PeerTube-8d2be0ed7bb87283a1ec98609df6b82d83db706a.tar.zst
PeerTube-8d2be0ed7bb87283a1ec98609df6b82d83db706a.zip
WIP plugins: move plugin CLI in peertube script
Install/uninstall/list plugins remotely
Diffstat (limited to 'server/controllers/api/plugins.ts')
-rw-r--r--server/controllers/api/plugins.ts16
1 files changed, 12 insertions, 4 deletions
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 {
21import { PluginManager } from '../../lib/plugins/plugin-manager' 21import { PluginManager } from '../../lib/plugins/plugin-manager'
22import { InstallPlugin } from '../../../shared/models/plugins/install-plugin.model' 22import { InstallPlugin } from '../../../shared/models/plugins/install-plugin.model'
23import { ManagePlugin } from '../../../shared/models/plugins/manage-plugin.model' 23import { ManagePlugin } from '../../../shared/models/plugins/manage-plugin.model'
24import { logger } from '../../helpers/logger'
24 25
25const pluginRouter = express.Router() 26const pluginRouter = express.Router()
26 27
@@ -46,7 +47,7 @@ pluginRouter.get('/:npmName/registered-settings',
46 authenticate, 47 authenticate,
47 ensureUserHasRight(UserRight.MANAGE_PLUGINS), 48 ensureUserHasRight(UserRight.MANAGE_PLUGINS),
48 asyncMiddleware(existingPluginValidator), 49 asyncMiddleware(existingPluginValidator),
49 asyncMiddleware(getPluginRegisteredSettings) 50 getPluginRegisteredSettings
50) 51)
51 52
52pluginRouter.put('/:npmName/settings', 53pluginRouter.put('/:npmName/settings',
@@ -101,7 +102,14 @@ function getPlugin (req: express.Request, res: express.Response) {
101async function installPlugin (req: express.Request, res: express.Response) { 102async function installPlugin (req: express.Request, res: express.Response) {
102 const body: InstallPlugin = req.body 103 const body: InstallPlugin = req.body
103 104
104 await PluginManager.Instance.install(body.npmName) 105 const fromDisk = !!body.path
106 const toInstall = body.npmName || body.path
107 try {
108 await PluginManager.Instance.install(toInstall, undefined, fromDisk)
109 } catch (err) {
110 logger.warn('Cannot install plugin %s.', toInstall, { err })
111 return res.sendStatus(400)
112 }
105 113
106 return res.sendStatus(204) 114 return res.sendStatus(204)
107} 115}
@@ -114,10 +122,10 @@ async function uninstallPlugin (req: express.Request, res: express.Response) {
114 return res.sendStatus(204) 122 return res.sendStatus(204)
115} 123}
116 124
117async function getPluginRegisteredSettings (req: express.Request, res: express.Response) { 125function getPluginRegisteredSettings (req: express.Request, res: express.Response) {
118 const plugin = res.locals.plugin 126 const plugin = res.locals.plugin
119 127
120 const settings = await PluginManager.Instance.getSettings(plugin.name) 128 const settings = PluginManager.Instance.getSettings(plugin.name)
121 129
122 return res.json({ 130 return res.json({
123 settings 131 settings