X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Fplugins%2Fplugin-manager.ts;h=eab0b39780d9bcc8bc702028c086b3036c602555;hb=b7221c1d94e088231ef28b11d95d45d781fbe41c;hp=c4d9b65740a9cc0e1779841475e41d10effb64bb;hpb=2f061e065ab43cc0b73595b619639a92952aeeba;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/plugins/plugin-manager.ts b/server/lib/plugins/plugin-manager.ts index c4d9b6574..eab0b3978 100644 --- a/server/lib/plugins/plugin-manager.ts +++ b/server/lib/plugins/plugin-manager.ts @@ -79,6 +79,10 @@ export class PluginManager implements ServerHook { registerWebSocketRouter () { this.server.on('upgrade', (request, socket, head) => { + // Check if it's a plugin websocket connection + // No need to destroy the stream when we abort the request + // Other handlers in PeerTube will catch this upgrade event too (socket.io, tracker etc) + const url = request.url const matched = url.match(`/plugins/([^/]+)/([^/]+/)?ws(/.*)`) @@ -95,7 +99,11 @@ export class PluginManager implements ServerHook { const wss = routes.find(r => r.route.startsWith(subRoute)) if (!wss) return - wss.handler(request, socket, head) + try { + wss.handler(request, socket, head) + } catch (err) { + logger.error('Exception in plugin handler ' + npmName, { err }) + } }) } @@ -317,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 @@ -349,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 }) @@ -386,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 = 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)