+
+ private buildPeerTubeHelpers (pluginInfo: PluginInfo): RegisterClientHelpers {
+ const { plugin } = pluginInfo
+ const npmName = this.nameToNpmName(pluginInfo.plugin.name, pluginInfo.pluginType)
+
+ return {
+ getBaseStaticRoute: () => {
+ const pathPrefix = this.getPluginPathPrefix(pluginInfo.isTheme)
+ return environment.apiUrl + `${pathPrefix}/${plugin.name}/${plugin.version}/static`
+ },
+
+ getSettings: () => {
+ const path = PluginService.BASE_PLUGIN_API_URL + '/' + npmName + '/public-settings'
+
+ return this.authHttp.get<PublicServerSetting>(path)
+ .pipe(
+ map(p => p.publicSettings),
+ catchError(res => this.restExtractor.handleError(res))
+ )
+ .toPromise()
+ },
+
+ isLoggedIn: () => {
+ return this.authService.isLoggedIn()
+ },
+
+ 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),
+ success: (text: string, title?: string, timeout?: number) => this.notifier.success(text, title, timeout)
+ },
+
+ showModal: (input: {
+ title: string,
+ content: string,
+ close?: boolean,
+ cancel?: { value: string, action?: () => void },
+ confirm?: { value: string, action?: () => void }
+ }) => {
+ this.customModal.show(input)
+ },
+
+ markdownRenderer: {
+ textMarkdownToHTML: (textMarkdown: string) => {
+ return this.markdownRenderer.textMarkdownToHTML(textMarkdown)
+ },
+
+ enhancedMarkdownToHTML: (enhancedMarkdown: string) => {
+ return this.markdownRenderer.enhancedMarkdownToHTML(enhancedMarkdown)
+ }
+ },
+
+ translate: (value: string) => {
+ return this.translationsObservable
+ .pipe(map(allTranslations => allTranslations[npmName]))
+ .pipe(map(translations => peertubeTranslate(value, translations)))
+ .toPromise()
+ }
+ }
+ }
+
+ private loadTranslations () {
+ const completeLocale = isOnDevLocale() ? getDevLocale() : getCompleteLocale(this.localeId)
+
+ // Default locale, nothing to translate
+ if (isDefaultLocale(completeLocale)) this.translationsObservable = of({}).pipe(shareReplay())
+
+ this.translationsObservable = this.authHttp
+ .get<PluginTranslation>(PluginService.BASE_PLUGIN_URL + '/translations/' + completeLocale + '.json')
+ .pipe(shareReplay())
+ }
+
+ private getPluginPathPrefix (isTheme: boolean) {
+ return isTheme ? '/themes' : '/plugins'
+ }