]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Don't call plugin register/unregister methods
authorChocobozzz <me@florianbigard.com>
Fri, 5 May 2023 12:14:26 +0000 (14:14 +0200)
committerChocobozzz <me@florianbigard.com>
Fri, 5 May 2023 12:24:27 +0000 (14:24 +0200)
scripts/plugin/install.ts
scripts/plugin/uninstall.ts
server/controllers/api/plugins.ts
server/lib/plugins/plugin-manager.ts

index 0795d7c935673fee073444be618d0d5672bd9b2a..138f34446ef81ea8f687b49ba205a1e07672c06a 100755 (executable)
@@ -32,5 +32,10 @@ async function run () {
   await initDatabaseModels(true)
 
   const toInstall = options.npmName || options.pluginPath
-  await PluginManager.Instance.install(toInstall, options.pluginVersion, !!options.pluginPath)
+  await PluginManager.Instance.install({
+    toInstall,
+    version: options.pluginVersion,
+    fromDisk: !!options.pluginPath,
+    register: false
+  })
 }
index 152b651dd498216ecab693651f9b96e1c8e18c27..7705946856a20de6d817d8d8b6987fd654e943be 100755 (executable)
@@ -25,5 +25,5 @@ async function run () {
   await initDatabaseModels(true)
 
   const toUninstall = options.npmName
-  await PluginManager.Instance.uninstall(toUninstall)
+  await PluginManager.Instance.uninstall({ npmName: toUninstall, unregister: false })
 }
index de9e055dc0fe4b9bf7db4b7c0a5484237a44ebc9..e85fd6e116207c8642ff8bcec92b50f244ff196d 100644 (file)
@@ -150,7 +150,7 @@ async function installPlugin (req: express.Request, res: express.Response) {
     : undefined
 
   try {
-    const plugin = await PluginManager.Instance.install(toInstall, pluginVersion, fromDisk)
+    const plugin = await PluginManager.Instance.install({ toInstall, version: pluginVersion, fromDisk })
 
     return res.json(plugin.toFormattedJSON())
   } catch (err) {
@@ -177,7 +177,7 @@ async function updatePlugin (req: express.Request, res: express.Response) {
 async function uninstallPlugin (req: express.Request, res: express.Response) {
   const body: ManagePlugin = req.body
 
-  await PluginManager.Instance.uninstall(body.npmName)
+  await PluginManager.Instance.uninstall({ npmName: body.npmName })
 
   return res.status(HttpStatusCode.NO_CONTENT_204).end()
 }
index d368aecfc282fea5487650e3852b8289ca1fba7e..ca72753663541507cf2329912dedcbfaff934190 100644 (file)
@@ -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,12 +364,14 @@ 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)
+        await this.uninstall({ npmName })
       } catch (err) {
         logger.error('Cannot uninstall plugin %s after failed installation.', toInstall, { err })
 
@@ -394,16 +403,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 } = 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)