]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/core/plugins/plugin.service.ts
Add auth user client hook actions
[github/Chocobozzz/PeerTube.git] / client / src / app / core / plugins / plugin.service.ts
index 871613b89f6712f86a04f4e84eba6c9902106f74..54dba5e178b5ee8095bb57ec58cd74a65335f0fc 100644 (file)
@@ -2,6 +2,7 @@ import { Observable, of, ReplaySubject } from 'rxjs'
 import { catchError, first, map, shareReplay } from 'rxjs/operators'
 import { HttpClient } from '@angular/common/http'
 import { Inject, Injectable, LOCALE_ID, NgZone } from '@angular/core'
+import { VideoEditType } from '@app/+videos/+video-edit/shared/video-edit.type'
 import { AuthService } from '@app/core/auth'
 import { Notifier } from '@app/core/notification'
 import { MarkdownService } from '@app/core/renderer'
@@ -9,7 +10,7 @@ import { RestExtractor } from '@app/core/rest'
 import { ServerService } from '@app/core/server/server.service'
 import { getDevLocale, isOnDevLocale } from '@app/helpers'
 import { CustomModalComponent } from '@app/modal/custom-modal.component'
-import { Hooks, loadPlugin, PluginInfo, runHook } from '@root-helpers/plugins'
+import { FormFields, Hooks, loadPlugin, PluginInfo, runHook } from '@root-helpers/plugins'
 import { getCompleteLocale, isDefaultLocale, peertubeTranslate } from '@shared/core-utils/i18n'
 import {
   ClientHook,
@@ -36,6 +37,7 @@ export class PluginService implements ClientHook {
     'video-watch': new ReplaySubject<boolean>(1),
     signup: new ReplaySubject<boolean>(1),
     login: new ReplaySubject<boolean>(1),
+    'video-edit': new ReplaySubject<boolean>(1),
     embed: new ReplaySubject<boolean>(1)
   }
 
@@ -50,6 +52,9 @@ export class PluginService implements ClientHook {
   private loadingScopes: { [id in PluginClientScope]?: boolean } = {}
 
   private hooks: Hooks = {}
+  private formFields: FormFields = {
+    video: []
+  }
 
   constructor (
     private authService: AuthService,
@@ -188,9 +193,18 @@ export class PluginService implements ClientHook {
       : PluginType.THEME
   }
 
+  getRegisteredVideoFormFields (type: VideoEditType) {
+    return this.formFields.video.filter(f => f.videoFormOptions.type === type)
+  }
+
   private loadPlugin (pluginInfo: PluginInfo) {
     return this.zone.runOutsideAngular(() => {
-      return loadPlugin(this.hooks, pluginInfo, pluginInfo => this.buildPeerTubeHelpers(pluginInfo))
+      return loadPlugin({
+        hooks: this.hooks,
+        formFields: this.formFields,
+        pluginInfo,
+        peertubeHelpersFactory: pluginInfo => this.buildPeerTubeHelpers(pluginInfo)
+      })
     })
   }
 
@@ -221,6 +235,12 @@ export class PluginService implements ClientHook {
                    .toPromise()
       },
 
+      getServerConfig: () => {
+        return this.server.getConfig()
+          .pipe(catchError(res => this.restExtractor.handleError(res)))
+          .toPromise()
+      },
+
       isLoggedIn: () => {
         return this.authService.isLoggedIn()
       },