aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/root-helpers/plugins-manager.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/root-helpers/plugins-manager.ts')
-rw-r--r--client/src/root-helpers/plugins-manager.ts23
1 files changed, 12 insertions, 11 deletions
diff --git a/client/src/root-helpers/plugins-manager.ts b/client/src/root-helpers/plugins-manager.ts
index 49a19781b..37a52be72 100644
--- a/client/src/root-helpers/plugins-manager.ts
+++ b/client/src/root-helpers/plugins-manager.ts
@@ -21,6 +21,7 @@ import {
21} from '@shared/models' 21} from '@shared/models'
22import { environment } from '../environments/environment' 22import { environment } from '../environments/environment'
23import { ClientScript } from '../types' 23import { ClientScript } from '../types'
24import { logger } from './logger'
24 25
25interface HookStructValue extends RegisterClientHookOptions { 26interface HookStructValue extends RegisterClientHookOptions {
26 plugin: ServerConfigPlugin 27 plugin: ServerConfigPlugin
@@ -48,7 +49,7 @@ type OnSettingsScripts = (pluginInfo: PluginInfo, options: RegisterClientSetting
48 49
49type OnClientRoute = (options: RegisterClientRouteOptions) => void 50type OnClientRoute = (options: RegisterClientRouteOptions) => void
50 51
51const logger = debug('peertube:plugins') 52const debugLogger = debug('peertube:plugins')
52 53
53class PluginsManager { 54class PluginsManager {
54 private hooks: Hooks = {} 55 private hooks: Hooks = {}
@@ -109,10 +110,10 @@ class PluginsManager {
109 const hookType = getHookType(hookName) 110 const hookType = getHookType(hookName)
110 111
111 for (const hook of this.hooks[hookName]) { 112 for (const hook of this.hooks[hookName]) {
112 console.log('Running hook %s of plugin %s.', hookName, hook.plugin.name) 113 logger.info(`Running hook ${hookName} of plugin ${hook.plugin.name}`)
113 114
114 result = await internalRunHook(hook.handler, hookType, result, params, err => { 115 result = await internalRunHook(hook.handler, hookType, result, params, err => {
115 console.error('Cannot run hook %s of script %s of plugin %s.', hookName, hook.clientScript.script, hook.plugin.name, err) 116 logger.error(`Cannot run hook ${hookName} of script ${hook.clientScript.script} of plugin ${hook.plugin.name}`, err)
116 }) 117 })
117 } 118 }
118 119
@@ -170,7 +171,7 @@ class PluginsManager {
170 171
171 this.loadingScopes[scope] = true 172 this.loadingScopes[scope] = true
172 173
173 logger('Loading scope %s', scope) 174 debugLogger('Loading scope %s', scope)
174 175
175 try { 176 try {
176 if (!isReload) this.loadedScopes.push(scope) 177 if (!isReload) this.loadedScopes.push(scope)
@@ -180,7 +181,7 @@ class PluginsManager {
180 this.loadingScopes[scope] = false 181 this.loadingScopes[scope] = false
181 this.pluginsLoaded[scope].next(true) 182 this.pluginsLoaded[scope].next(true)
182 183
183 logger('Nothing to load for scope %s', scope) 184 debugLogger('Nothing to load for scope %s', scope)
184 return 185 return
185 } 186 }
186 187
@@ -200,9 +201,9 @@ class PluginsManager {
200 this.pluginsLoaded[scope].next(true) 201 this.pluginsLoaded[scope].next(true)
201 this.loadingScopes[scope] = false 202 this.loadingScopes[scope] = false
202 203
203 logger('Scope %s loaded', scope) 204 debugLogger('Scope %s loaded', scope)
204 } catch (err) { 205 } catch (err) {
205 console.error('Cannot load plugins by scope %s.', scope, err) 206 logger.error(`Cannot load plugins by scope ${scope}`, err)
206 } 207 }
207 } 208 }
208 209
@@ -211,7 +212,7 @@ class PluginsManager {
211 212
212 const registerHook = (options: RegisterClientHookOptions) => { 213 const registerHook = (options: RegisterClientHookOptions) => {
213 if (clientHookObject[options.target] !== true) { 214 if (clientHookObject[options.target] !== true) {
214 console.error('Unknown hook %s of plugin %s. Skipping.', options.target, plugin.name) 215 logger.error(`Unknown hook ${options.target} of plugin ${plugin.name}. Skipping.`)
215 return 216 return
216 } 217 }
217 218
@@ -252,7 +253,7 @@ class PluginsManager {
252 253
253 const peertubeHelpers = this.peertubeHelpersFactory(pluginInfo) 254 const peertubeHelpers = this.peertubeHelpersFactory(pluginInfo)
254 255
255 console.log('Loading script %s of plugin %s.', clientScript.script, plugin.name) 256 logger.info(`Loading script ${clientScript.script} of plugin ${plugin.name}`)
256 257
257 const absURL = (environment.apiUrl || window.location.origin) + clientScript.script 258 const absURL = (environment.apiUrl || window.location.origin) + clientScript.script
258 return dynamicImport(absURL) 259 return dynamicImport(absURL)
@@ -266,7 +267,7 @@ class PluginsManager {
266 }) 267 })
267 }) 268 })
268 .then(() => this.sortHooksByPriority()) 269 .then(() => this.sortHooksByPriority())
269 .catch(err => console.error('Cannot import or register plugin %s.', pluginInfo.plugin.name, err)) 270 .catch(err => logger.error(`Cannot import or register plugin ${pluginInfo.plugin.name}`, err))
270 } 271 }
271 272
272 private sortHooksByPriority () { 273 private sortHooksByPriority () {
@@ -294,7 +295,7 @@ async function dynamicImport (url: string) {
294 // eslint-disable-next-line no-new-func 295 // eslint-disable-next-line no-new-func
295 return new Function(`return import('${url}')`)() 296 return new Function(`return import('${url}')`)()
296 } catch { 297 } catch {
297 console.log('Fallback to import polyfill') 298 logger.info('Fallback to import polyfill')
298 299
299 return new Promise((resolve, reject) => { 300 return new Promise((resolve, reject) => {
300 const vector = '$importModule$' + Math.random().toString(32).slice(2) 301 const vector = '$importModule$' + Math.random().toString(32).slice(2)