-import { Observable, of } from 'rxjs'
+import { firstValueFrom, Observable, of } from 'rxjs'
import { catchError, map, shareReplay } from 'rxjs/operators'
import { HttpClient } from '@angular/common/http'
import { Inject, Injectable, LOCALE_ID, NgZone } from '@angular/core'
PluginType,
PublicServerSetting,
RegisterClientFormFieldOptions,
- RegisterClientSettingsScript,
+ RegisterClientSettingsScriptOptions,
+ RegisterClientRouteOptions,
RegisterClientVideoFieldOptions,
ServerConfigPlugin
} from '@shared/models'
private formFields: FormFields = {
video: []
}
- private settingsScripts: { [ npmName: string ]: RegisterClientSettingsScript } = {}
+ private settingsScripts: { [ npmName: string ]: RegisterClientSettingsScriptOptions } = {}
+ private clientRoutes: { [ route: string ]: RegisterClientRouteOptions } = {}
private pluginsManager: PluginsManager
this.pluginsManager = new PluginsManager({
peertubeHelpersFactory: this.buildPeerTubeHelpers.bind(this),
onFormFields: this.onFormFields.bind(this),
- onSettingsScripts: this.onSettingsScripts.bind(this)
+ onSettingsScripts: this.onSettingsScripts.bind(this),
+ onClientRoute: this.onClientRoute.bind(this)
})
}
return this.settingsScripts[npmName]
}
+ getRegisteredClientRoute (route: string) {
+ return this.clientRoutes[route]
+ }
+
+ getAllRegisteredClientRoutes () {
+ return Object.keys(this.clientRoutes)
+ }
+
translateBy (npmName: string, toTranslate: string) {
const helpers = this.helpers[npmName]
if (!helpers) {
})
}
- private onSettingsScripts (pluginInfo: PluginInfo, options: RegisterClientSettingsScript) {
+ private onSettingsScripts (pluginInfo: PluginInfo, options: RegisterClientSettingsScriptOptions) {
const npmName = this.nameToNpmName(pluginInfo.plugin.name, pluginInfo.pluginType)
this.settingsScripts[npmName] = options
}
+ private onClientRoute (options: RegisterClientRouteOptions) {
+ const route = options.route.startsWith('/')
+ ? options.route
+ : `/${options.route}`
+
+ this.clientRoutes[route] = options
+ }
+
private buildPeerTubeHelpers (pluginInfo: PluginInfo): RegisterClientHelpers {
const { plugin } = pluginInfo
const npmName = this.nameToNpmName(pluginInfo.plugin.name, pluginInfo.pluginType)
return environment.apiUrl + `${pathPrefix}/${plugin.name}/${plugin.version}/router`
},
+ getBasePluginClientPath: () => {
+ return '/p'
+ },
+
getSettings: () => {
const path = PluginService.BASE_PLUGIN_API_URL + '/' + npmName + '/public-settings'
- return this.authHttp.get<PublicServerSetting>(path)
+ const obs = this.authHttp.get<PublicServerSetting>(path)
.pipe(
map(p => p.publicSettings),
catchError(res => this.restExtractor.handleError(res))
)
- .toPromise()
+
+ return firstValueFrom(obs)
},
getServerConfig: () => {
- return this.server.getConfig()
+ const obs = this.server.getConfig()
.pipe(catchError(res => this.restExtractor.handleError(res)))
- .toPromise()
+
+ return firstValueFrom(obs)
},
isLoggedIn: () => {
if (!this.authService.isLoggedIn()) return undefined
const value = this.authService.getRequestHeaderValue()
- return { 'Authorization': value }
+ return { Authorization: value }
},
notifier: {
},
showModal: (input: {
- title: string,
- content: string,
- close?: boolean,
- cancel?: { value: string, action?: () => void },
+ title: string
+ content: string
+ close?: boolean
+ cancel?: { value: string, action?: () => void }
confirm?: { value: string, action?: () => void }
}) => {
this.zone.run(() => this.customModal.show(input))
},
translate: (value: string) => {
- return this.translationsObservable
+ const obs = this.translationsObservable
.pipe(map(allTranslations => allTranslations[npmName]))
.pipe(map(translations => peertubeTranslate(value, translations)))
- .toPromise()
+
+ return firstValueFrom(obs)
}
}
}