diff options
Diffstat (limited to 'server/controllers/api')
-rw-r--r-- | server/controllers/api/plugins.ts | 16 |
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 { | |||
21 | import { PluginManager } from '../../lib/plugins/plugin-manager' | 21 | import { PluginManager } from '../../lib/plugins/plugin-manager' |
22 | import { InstallPlugin } from '../../../shared/models/plugins/install-plugin.model' | 22 | import { InstallPlugin } from '../../../shared/models/plugins/install-plugin.model' |
23 | import { ManagePlugin } from '../../../shared/models/plugins/manage-plugin.model' | 23 | import { ManagePlugin } from '../../../shared/models/plugins/manage-plugin.model' |
24 | import { logger } from '../../helpers/logger' | ||
24 | 25 | ||
25 | const pluginRouter = express.Router() | 26 | const 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 | ||
52 | pluginRouter.put('/:npmName/settings', | 53 | pluginRouter.put('/:npmName/settings', |
@@ -101,7 +102,14 @@ function getPlugin (req: express.Request, res: express.Response) { | |||
101 | async function installPlugin (req: express.Request, res: express.Response) { | 102 | async 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 | ||
117 | async function getPluginRegisteredSettings (req: express.Request, res: express.Response) { | 125 | function 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 |