X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Fplugins%2Fplugin-manager.ts;h=9086a4c8e855b2343fb77ddb9f49262bd001a81b;hb=f86ff3a02642263ac64db5d5fba4059db0092561;hp=d368aecfc282fea5487650e3852b8289ca1fba7e;hpb=82d1653d799ccc0bcc228bb5e5aafef7a071c2db;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/plugins/plugin-manager.ts b/server/lib/plugins/plugin-manager.ts index d368aecfc..9086a4c8e 100644 --- a/server/lib/plugins/plugin-manager.ts +++ b/server/lib/plugins/plugin-manager.ts @@ -325,7 +325,14 @@ export class PluginManager implements ServerHook { // ###################### Installation ###################### - async install (toInstall: string, version?: string, fromDisk = false) { + async install (options: { + toInstall: string + version?: string + fromDisk?: boolean // default false + register?: boolean // default true + }) { + const { toInstall, version, fromDisk = false, register = true } = options + let plugin: PluginModel let npmName: string @@ -357,19 +364,23 @@ export class PluginManager implements ServerHook { logger.info('Successful installation of plugin %s.', toInstall) - await this.registerPluginOrTheme(plugin) + if (register) { + await this.registerPluginOrTheme(plugin) + } } catch (rootErr) { logger.error('Cannot install plugin %s, removing it...', toInstall, { err: rootErr }) - try { - await this.uninstall(npmName) - } catch (err) { - logger.error('Cannot uninstall plugin %s after failed installation.', toInstall, { err }) - + if (npmName) { try { - await removeNpmPlugin(npmName) + await this.uninstall({ npmName }) } catch (err) { - logger.error('Cannot remove plugin %s after failed installation.', toInstall, { err }) + logger.error('Cannot uninstall plugin %s after failed installation.', toInstall, { err }) + + try { + await removeNpmPlugin(npmName) + } catch (err) { + logger.error('Cannot remove plugin %s after failed installation.', toInstall, { err }) + } } } @@ -394,16 +405,23 @@ export class PluginManager implements ServerHook { // Unregister old hooks await this.unregister(npmName) - return this.install(toUpdate, version, fromDisk) + return this.install({ toInstall: toUpdate, version, fromDisk }) } - async uninstall (npmName: string) { + async uninstall (options: { + npmName: string + unregister?: boolean // default true + }) { + const { npmName, unregister = true } = options + logger.info('Uninstalling plugin %s.', npmName) - try { - await this.unregister(npmName) - } catch (err) { - logger.warn('Cannot unregister plugin %s.', npmName, { err }) + if (unregister) { + try { + await this.unregister(npmName) + } catch (err) { + logger.warn('Cannot unregister plugin %s.', npmName, { err }) + } } const plugin = await PluginModel.loadByNpmName(npmName)