diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/controllers/api/plugins.ts | 4 | ||||
-rw-r--r-- | server/lib/plugins/plugin-manager.ts | 34 |
2 files changed, 27 insertions, 11 deletions
diff --git a/server/controllers/api/plugins.ts b/server/controllers/api/plugins.ts index de9e055dc..e85fd6e11 100644 --- a/server/controllers/api/plugins.ts +++ b/server/controllers/api/plugins.ts | |||
@@ -150,7 +150,7 @@ async function installPlugin (req: express.Request, res: express.Response) { | |||
150 | : undefined | 150 | : undefined |
151 | 151 | ||
152 | try { | 152 | try { |
153 | const plugin = await PluginManager.Instance.install(toInstall, pluginVersion, fromDisk) | 153 | const plugin = await PluginManager.Instance.install({ toInstall, version: pluginVersion, fromDisk }) |
154 | 154 | ||
155 | return res.json(plugin.toFormattedJSON()) | 155 | return res.json(plugin.toFormattedJSON()) |
156 | } catch (err) { | 156 | } catch (err) { |
@@ -177,7 +177,7 @@ async function updatePlugin (req: express.Request, res: express.Response) { | |||
177 | async function uninstallPlugin (req: express.Request, res: express.Response) { | 177 | async function uninstallPlugin (req: express.Request, res: express.Response) { |
178 | const body: ManagePlugin = req.body | 178 | const body: ManagePlugin = req.body |
179 | 179 | ||
180 | await PluginManager.Instance.uninstall(body.npmName) | 180 | await PluginManager.Instance.uninstall({ npmName: body.npmName }) |
181 | 181 | ||
182 | return res.status(HttpStatusCode.NO_CONTENT_204).end() | 182 | return res.status(HttpStatusCode.NO_CONTENT_204).end() |
183 | } | 183 | } |
diff --git a/server/lib/plugins/plugin-manager.ts b/server/lib/plugins/plugin-manager.ts index d368aecfc..ca7275366 100644 --- a/server/lib/plugins/plugin-manager.ts +++ b/server/lib/plugins/plugin-manager.ts | |||
@@ -325,7 +325,14 @@ export class PluginManager implements ServerHook { | |||
325 | 325 | ||
326 | // ###################### Installation ###################### | 326 | // ###################### Installation ###################### |
327 | 327 | ||
328 | async install (toInstall: string, version?: string, fromDisk = false) { | 328 | async install (options: { |
329 | toInstall: string | ||
330 | version?: string | ||
331 | fromDisk?: boolean // default false | ||
332 | register?: boolean // default true | ||
333 | }) { | ||
334 | const { toInstall, version, fromDisk = false, register = true } = options | ||
335 | |||
329 | let plugin: PluginModel | 336 | let plugin: PluginModel |
330 | let npmName: string | 337 | let npmName: string |
331 | 338 | ||
@@ -357,12 +364,14 @@ export class PluginManager implements ServerHook { | |||
357 | 364 | ||
358 | logger.info('Successful installation of plugin %s.', toInstall) | 365 | logger.info('Successful installation of plugin %s.', toInstall) |
359 | 366 | ||
360 | await this.registerPluginOrTheme(plugin) | 367 | if (register) { |
368 | await this.registerPluginOrTheme(plugin) | ||
369 | } | ||
361 | } catch (rootErr) { | 370 | } catch (rootErr) { |
362 | logger.error('Cannot install plugin %s, removing it...', toInstall, { err: rootErr }) | 371 | logger.error('Cannot install plugin %s, removing it...', toInstall, { err: rootErr }) |
363 | 372 | ||
364 | try { | 373 | try { |
365 | await this.uninstall(npmName) | 374 | await this.uninstall({ npmName }) |
366 | } catch (err) { | 375 | } catch (err) { |
367 | logger.error('Cannot uninstall plugin %s after failed installation.', toInstall, { err }) | 376 | logger.error('Cannot uninstall plugin %s after failed installation.', toInstall, { err }) |
368 | 377 | ||
@@ -394,16 +403,23 @@ export class PluginManager implements ServerHook { | |||
394 | // Unregister old hooks | 403 | // Unregister old hooks |
395 | await this.unregister(npmName) | 404 | await this.unregister(npmName) |
396 | 405 | ||
397 | return this.install(toUpdate, version, fromDisk) | 406 | return this.install({ toInstall: toUpdate, version, fromDisk }) |
398 | } | 407 | } |
399 | 408 | ||
400 | async uninstall (npmName: string) { | 409 | async uninstall (options: { |
410 | npmName: string | ||
411 | unregister?: boolean // default true | ||
412 | }) { | ||
413 | const { npmName, unregister } = options | ||
414 | |||
401 | logger.info('Uninstalling plugin %s.', npmName) | 415 | logger.info('Uninstalling plugin %s.', npmName) |
402 | 416 | ||
403 | try { | 417 | if (unregister) { |
404 | await this.unregister(npmName) | 418 | try { |
405 | } catch (err) { | 419 | await this.unregister(npmName) |
406 | logger.warn('Cannot unregister plugin %s.', npmName, { err }) | 420 | } catch (err) { |
421 | logger.warn('Cannot unregister plugin %s.', npmName, { err }) | ||
422 | } | ||
407 | } | 423 | } |
408 | 424 | ||
409 | const plugin = await PluginModel.loadByNpmName(npmName) | 425 | const plugin = await PluginModel.loadByNpmName(npmName) |