]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/core/plugins/plugin.service.ts
Add debug logs to plugin service
[github/Chocobozzz/PeerTube.git] / client / src / app / core / plugins / plugin.service.ts
index 1243bac6791d362f87ba4cb0e846310302e12209..dff8ad864754469790b04c1f9a552cfda236de34 100644 (file)
@@ -24,6 +24,9 @@ import {
 } from '@shared/models'
 import { environment } from '../../../environments/environment'
 import { RegisterClientHelpers } from '../../../types/register-client-option.model'
+import * as debug from 'debug'
+
+const logger = debug('peertube:plugins')
 
 @Injectable()
 export class PluginService implements ClientHook {
@@ -34,6 +37,7 @@ export class PluginService implements ClientHook {
 
   pluginsLoaded: { [ scope in PluginClientScope ]: ReplaySubject<boolean> } = {
     common: new ReplaySubject<boolean>(1),
+    'admin-plugin': new ReplaySubject<boolean>(1),
     search: new ReplaySubject<boolean>(1),
     'video-watch': new ReplaySubject<boolean>(1),
     signup: new ReplaySubject<boolean>(1),
@@ -75,6 +79,8 @@ export class PluginService implements ClientHook {
   }
 
   initializePlugins () {
+    logger('Building plugin configuration')
+
     this.server.getConfig()
       .subscribe(config => {
         this.plugins = config.plugin.registered
@@ -82,6 +88,8 @@ export class PluginService implements ClientHook {
         this.buildScopeStruct()
 
         this.pluginsBuilt.next(true)
+
+        logger('Plugin configuration built')
       })
   }
 
@@ -145,6 +153,8 @@ export class PluginService implements ClientHook {
 
     this.loadingScopes[scope] = true
 
+    logger('Loading scope %s', scope)
+
     try {
       await this.ensurePluginsAreBuilt()
 
@@ -155,6 +165,7 @@ export class PluginService implements ClientHook {
         this.loadingScopes[scope] = false
         this.pluginsLoaded[scope].next(true)
 
+        logger('Nothing to load for scope %s', scope)
         return
       }
 
@@ -173,6 +184,8 @@ export class PluginService implements ClientHook {
 
       this.pluginsLoaded[scope].next(true)
       this.loadingScopes[scope] = false
+
+      logger('Scope %s loaded', scope)
     } catch (err) {
       console.error('Cannot load plugins by scope %s.', scope, err)
     }
@@ -249,6 +262,11 @@ export class PluginService implements ClientHook {
         return environment.apiUrl + `${pathPrefix}/${plugin.name}/${plugin.version}/static`
       },
 
+      getBaseRouterRoute: () => {
+        const pathPrefix = this.getPluginPathPrefix(pluginInfo.isTheme)
+        return environment.apiUrl + `${pathPrefix}/${plugin.name}/${plugin.version}/router`
+      },
+
       getSettings: () => {
         const path = PluginService.BASE_PLUGIN_API_URL + '/' + npmName + '/public-settings'
 
@@ -270,6 +288,13 @@ export class PluginService implements ClientHook {
         return this.authService.isLoggedIn()
       },
 
+      getAuthHeader: () => {
+        if (!this.authService.isLoggedIn()) return undefined
+
+        const value = this.authService.getRequestHeaderValue()
+        return { 'Authorization': value }
+      },
+
       notifier: {
         info: (text: string, title?: string, timeout?: number) => this.notifier.info(text, title, timeout),
         error: (text: string, title?: string, timeout?: number) => this.notifier.error(text, title, timeout),