import { PeerTubePlugin } from '@shared/models/plugins/peertube-plugin.model'
import { ActivatedRoute, Router } from '@angular/router'
import { compareSemVer } from '@shared/core-utils/miscs/miscs'
+import { PluginService } from '@app/core/plugins/plugin.service'
@Component({
selector: 'my-plugin-list-installed',
constructor (
private i18n: I18n,
- private pluginService: PluginApiService,
+ private pluginService: PluginService,
+ private pluginApiService: PluginApiService,
private notifier: Notifier,
private confirmService: ConfirmService,
private router: Router,
private route: ActivatedRoute
) {
- this.pluginTypeOptions = this.pluginService.getPluginTypeOptions()
+ this.pluginTypeOptions = this.pluginApiService.getPluginTypeOptions()
}
ngOnInit () {
}
loadMorePlugins () {
- this.pluginService.getPlugins(this.pluginType, this.pagination, this.sort)
+ this.pluginApiService.getPlugins(this.pluginType, this.pagination, this.sort)
.subscribe(
res => {
this.plugins = this.plugins.concat(res.data)
)
if (res === false) return
- this.pluginService.uninstall(plugin.name, plugin.type)
+ this.pluginApiService.uninstall(plugin.name, plugin.type)
.subscribe(
() => {
this.notifier.success(this.i18n('{{pluginName}} uninstalled.', { pluginName: plugin.name }))
this.updating[updatingKey] = true
- this.pluginService.update(plugin.name, plugin.type)
+ this.pluginApiService.update(plugin.name, plugin.type)
.pipe()
.subscribe(
res => {
import { InstallOrUpdatePlugin } from '@shared/models/plugins/install-plugin.model'
import { PeerTubePluginIndex } from '@shared/models/plugins/peertube-plugin-index.model'
import { RegisterServerSettingOptions } from '@shared/models/plugins/register-server-setting.model'
+import { PluginService } from '@app/core/plugins/plugin.service'
@Injectable()
export class PluginApiService {
- private static BASE_APPLICATION_URL = environment.apiUrl + '/api/v1/plugins'
+ private static BASE_PLUGIN_URL = environment.apiUrl + '/api/v1/plugins'
constructor (
private authHttp: HttpClient,
private restExtractor: RestExtractor,
private restService: RestService,
- private i18n: I18n
+ private i18n: I18n,
+ private pluginService: PluginService
) { }
getPluginTypeOptions () {
params = this.restService.addRestGetParams(params, pagination, sort)
params = params.append('pluginType', pluginType.toString())
- return this.authHttp.get<ResultList<PeerTubePlugin>>(PluginApiService.BASE_APPLICATION_URL, { params })
+ return this.authHttp.get<ResultList<PeerTubePlugin>>(PluginApiService.BASE_PLUGIN_URL, { params })
.pipe(catchError(res => this.restExtractor.handleError(res)))
}
if (search) params = params.append('search', search)
- return this.authHttp.get<ResultList<PeerTubePluginIndex>>(PluginApiService.BASE_APPLICATION_URL + '/available', { params })
+ return this.authHttp.get<ResultList<PeerTubePluginIndex>>(PluginApiService.BASE_PLUGIN_URL + '/available', { params })
.pipe(catchError(res => this.restExtractor.handleError(res)))
}
getPlugin (npmName: string) {
- const path = PluginApiService.BASE_APPLICATION_URL + '/' + npmName
+ const path = PluginApiService.BASE_PLUGIN_URL + '/' + npmName
return this.authHttp.get<PeerTubePlugin>(path)
.pipe(catchError(res => this.restExtractor.handleError(res)))
}
getPluginRegisteredSettings (pluginName: string, pluginType: PluginType) {
- const path = PluginApiService.BASE_APPLICATION_URL + '/' + this.nameToNpmName(pluginName, pluginType) + '/registered-settings'
+ const npmName = this.pluginService.nameToNpmName(pluginName, pluginType)
+ const path = PluginApiService.BASE_PLUGIN_URL + '/' + npmName + '/registered-settings'
return this.authHttp.get<{ settings: RegisterServerSettingOptions[] }>(path)
.pipe(catchError(res => this.restExtractor.handleError(res)))
}
updatePluginSettings (pluginName: string, pluginType: PluginType, settings: any) {
- const path = PluginApiService.BASE_APPLICATION_URL + '/' + this.nameToNpmName(pluginName, pluginType) + '/settings'
+ const npmName = this.pluginService.nameToNpmName(pluginName, pluginType)
+ const path = PluginApiService.BASE_PLUGIN_URL + '/' + npmName + '/settings'
return this.authHttp.put(path, { settings })
.pipe(catchError(res => this.restExtractor.handleError(res)))
uninstall (pluginName: string, pluginType: PluginType) {
const body: ManagePlugin = {
- npmName: this.nameToNpmName(pluginName, pluginType)
+ npmName: this.pluginService.nameToNpmName(pluginName, pluginType)
}
- return this.authHttp.post(PluginApiService.BASE_APPLICATION_URL + '/uninstall', body)
+ return this.authHttp.post(PluginApiService.BASE_PLUGIN_URL + '/uninstall', body)
.pipe(catchError(res => this.restExtractor.handleError(res)))
}
update (pluginName: string, pluginType: PluginType) {
const body: ManagePlugin = {
- npmName: this.nameToNpmName(pluginName, pluginType)
+ npmName: this.pluginService.nameToNpmName(pluginName, pluginType)
}
- return this.authHttp.post(PluginApiService.BASE_APPLICATION_URL + '/update', body)
+ return this.authHttp.post(PluginApiService.BASE_PLUGIN_URL + '/update', body)
.pipe(catchError(res => this.restExtractor.handleError(res)))
}
npmName
}
- return this.authHttp.post(PluginApiService.BASE_APPLICATION_URL + '/install', body)
+ return this.authHttp.post(PluginApiService.BASE_PLUGIN_URL + '/install', body)
.pipe(catchError(res => this.restExtractor.handleError(res)))
}
-
- nameToNpmName (name: string, type: PluginType) {
- const prefix = type === PluginType.PLUGIN
- ? 'peertube-plugin-'
- : 'peertube-theme-'
-
- return prefix + name
- }
-
- pluginTypeFromNpmName (npmName: string) {
- return npmName.startsWith('peertube-plugin-')
- ? PluginType.PLUGIN
- : PluginType.THEME
- }
}
filter(pathname => !pathname || pathname === '/' || is18nPath(pathname))
).subscribe(() => this.redirectService.redirectToHomepage(true))
+ navigationEndEvent.subscribe(e => {
+ this.hooks.runAction('action:router.navigation-end', 'common', { path: e.url })
+ })
+
eventsObs.pipe(
filter((e: Event): e is GuardsCheckStart => e instanceof GuardsCheckStart),
filter(() => this.screenService.isInSmallView())
runAction<T, U extends ClientActionHookName> (hookName: U, scope: PluginClientScope, params?: T) {
this.pluginService.ensurePluginsAreLoaded(scope)
- .then(() => this.pluginService.runHook(hookName, params))
+ .then(() => this.pluginService.runHook(hookName, undefined, params))
.catch((err: any) => console.error('Fatal hook error.', { err }))
}
}
import { ClientScript as ClientScriptModule } from '../../../types/client-script.model'
import { environment } from '../../../environments/environment'
import { ReplaySubject } from 'rxjs'
-import { first, shareReplay } from 'rxjs/operators'
+import { catchError, first, map, shareReplay } from 'rxjs/operators'
import { getHookType, internalRunHook } from '@shared/core-utils/plugins/hooks'
import { ClientHook, ClientHookName, clientHookObject } from '@shared/models/plugins/client-hook.model'
import { PluginClientScope } from '@shared/models/plugins/plugin-client-scope.type'
import { RegisterClientHookOptions } from '@shared/models/plugins/register-client-hook.model'
+import { PeerTubePlugin } from '@shared/models/plugins/peertube-plugin.model'
+import { HttpClient } from '@angular/common/http'
+import { RestExtractor } from '@app/shared/rest'
+import { PluginType } from '@shared/models/plugins/plugin.type'
interface HookStructValue extends RegisterClientHookOptions {
plugin: ServerConfigPlugin
type PluginInfo = {
plugin: ServerConfigPlugin
clientScript: ClientScript
+ pluginType: PluginType
isTheme: boolean
}
@Injectable()
export class PluginService implements ClientHook {
+ private static BASE_PLUGIN_URL = environment.apiUrl + '/api/v1/plugins'
+
pluginsBuilt = new ReplaySubject<boolean>(1)
pluginsLoaded: { [ scope in PluginClientScope ]: ReplaySubject<boolean> } = {
constructor (
private router: Router,
- private server: ServerService
+ private server: ServerService,
+ private authHttp: HttpClient,
+ private restExtractor: RestExtractor
) {
}
script: environment.apiUrl + `${pathPrefix}/${plugin.name}/${plugin.version}/client-scripts/${clientScript.script}`,
scopes: clientScript.scopes
},
+ pluginType: isTheme ? PluginType.THEME : PluginType.PLUGIN,
isTheme
})
return result
}
+ nameToNpmName (name: string, type: PluginType) {
+ const prefix = type === PluginType.PLUGIN
+ ? 'peertube-plugin-'
+ : 'peertube-theme-'
+
+ return prefix + name
+ }
+
+ pluginTypeFromNpmName (npmName: string) {
+ return npmName.startsWith('peertube-plugin-')
+ ? PluginType.PLUGIN
+ : PluginType.THEME
+ }
+
private loadPlugin (pluginInfo: PluginInfo) {
const { plugin, clientScript } = pluginInfo
return import(/* webpackIgnore: true */ clientScript.script)
.then((script: ClientScriptModule) => script.register({ registerHook, peertubeHelpers }))
.then(() => this.sortHooksByPriority())
+ .catch(err => console.error('Cannot import or register plugin %s.', pluginInfo.plugin.name, err))
}
private buildScopeStruct () {
getBaseStaticRoute: () => {
const pathPrefix = this.getPluginPathPrefix(pluginInfo.isTheme)
return environment.apiUrl + `${pathPrefix}/${plugin.name}/${plugin.version}/static`
+ },
+
+ getSettings: () => {
+ const npmName = this.nameToNpmName(pluginInfo.plugin.name, pluginInfo.pluginType)
+ const path = PluginService.BASE_PLUGIN_URL + '/' + npmName
+
+ return this.authHttp.get<PeerTubePlugin>(path)
+ .pipe(
+ map(p => p.settings),
+ catchError(res => this.restExtractor.handleError(res))
+ )
+ .toPromise()
}
}
}
peertubeHelpers: {
getBaseStaticRoute: () => string
+
+ getSettings: () => Promise<{ [ name: string ]: string }>
}
}
}
delete this.registeredPlugins[plugin.npmName]
+ delete this.settings[plugin.npmName]
if (plugin.type === PluginType.PLUGIN) {
await plugin.unregister()
'action:video-watch.video.loaded': true,
// Fired when the search page is being initialized
- 'action:search.init': true
+ 'action:search.init': true,
+
+ // Fired every time Angular URL changes
+ 'action:router.navigation-end': true
}
export type ClientActionHookName = keyof typeof clientActionHookObject