diff options
author | Chocobozzz <me@florianbigard.com> | 2021-12-10 15:01:12 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-12-10 15:01:12 +0100 |
commit | d63e6d4604dfbe4938c7d66832c9202364c5bb64 (patch) | |
tree | 6bd444be722276ff214d911284a400e374bdddc8 /client/src/app/core/plugins | |
parent | 03a65456f44a6152bb68975e29e076c8c5754cd6 (diff) | |
download | PeerTube-d63e6d4604dfbe4938c7d66832c9202364c5bb64.tar.gz PeerTube-d63e6d4604dfbe4938c7d66832c9202364c5bb64.tar.zst PeerTube-d63e6d4604dfbe4938c7d66832c9202364c5bb64.zip |
Add ability for plugins to register client routes
Diffstat (limited to 'client/src/app/core/plugins')
-rw-r--r-- | client/src/app/core/plugins/plugin.service.ts | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/client/src/app/core/plugins/plugin.service.ts b/client/src/app/core/plugins/plugin.service.ts index 89391c2c5..fdbbd2d56 100644 --- a/client/src/app/core/plugins/plugin.service.ts +++ b/client/src/app/core/plugins/plugin.service.ts | |||
@@ -20,7 +20,8 @@ import { | |||
20 | PluginType, | 20 | PluginType, |
21 | PublicServerSetting, | 21 | PublicServerSetting, |
22 | RegisterClientFormFieldOptions, | 22 | RegisterClientFormFieldOptions, |
23 | RegisterClientSettingsScript, | 23 | RegisterClientSettingsScriptOptions, |
24 | RegisterClientRouteOptions, | ||
24 | RegisterClientVideoFieldOptions, | 25 | RegisterClientVideoFieldOptions, |
25 | ServerConfigPlugin | 26 | ServerConfigPlugin |
26 | } from '@shared/models' | 27 | } from '@shared/models' |
@@ -48,7 +49,8 @@ export class PluginService implements ClientHook { | |||
48 | private formFields: FormFields = { | 49 | private formFields: FormFields = { |
49 | video: [] | 50 | video: [] |
50 | } | 51 | } |
51 | private settingsScripts: { [ npmName: string ]: RegisterClientSettingsScript } = {} | 52 | private settingsScripts: { [ npmName: string ]: RegisterClientSettingsScriptOptions } = {} |
53 | private clientRoutes: { [ route: string ]: RegisterClientRouteOptions } = {} | ||
52 | 54 | ||
53 | private pluginsManager: PluginsManager | 55 | private pluginsManager: PluginsManager |
54 | 56 | ||
@@ -67,7 +69,8 @@ export class PluginService implements ClientHook { | |||
67 | this.pluginsManager = new PluginsManager({ | 69 | this.pluginsManager = new PluginsManager({ |
68 | peertubeHelpersFactory: this.buildPeerTubeHelpers.bind(this), | 70 | peertubeHelpersFactory: this.buildPeerTubeHelpers.bind(this), |
69 | onFormFields: this.onFormFields.bind(this), | 71 | onFormFields: this.onFormFields.bind(this), |
70 | onSettingsScripts: this.onSettingsScripts.bind(this) | 72 | onSettingsScripts: this.onSettingsScripts.bind(this), |
73 | onClientRoute: this.onClientRoute.bind(this) | ||
71 | }) | 74 | }) |
72 | } | 75 | } |
73 | 76 | ||
@@ -123,6 +126,14 @@ export class PluginService implements ClientHook { | |||
123 | return this.settingsScripts[npmName] | 126 | return this.settingsScripts[npmName] |
124 | } | 127 | } |
125 | 128 | ||
129 | getRegisteredClientRoute (route: string) { | ||
130 | return this.clientRoutes[route] | ||
131 | } | ||
132 | |||
133 | getAllRegisteredClientRoutes () { | ||
134 | return Object.keys(this.clientRoutes) | ||
135 | } | ||
136 | |||
126 | translateBy (npmName: string, toTranslate: string) { | 137 | translateBy (npmName: string, toTranslate: string) { |
127 | const helpers = this.helpers[npmName] | 138 | const helpers = this.helpers[npmName] |
128 | if (!helpers) { | 139 | if (!helpers) { |
@@ -140,12 +151,20 @@ export class PluginService implements ClientHook { | |||
140 | }) | 151 | }) |
141 | } | 152 | } |
142 | 153 | ||
143 | private onSettingsScripts (pluginInfo: PluginInfo, options: RegisterClientSettingsScript) { | 154 | private onSettingsScripts (pluginInfo: PluginInfo, options: RegisterClientSettingsScriptOptions) { |
144 | const npmName = this.nameToNpmName(pluginInfo.plugin.name, pluginInfo.pluginType) | 155 | const npmName = this.nameToNpmName(pluginInfo.plugin.name, pluginInfo.pluginType) |
145 | 156 | ||
146 | this.settingsScripts[npmName] = options | 157 | this.settingsScripts[npmName] = options |
147 | } | 158 | } |
148 | 159 | ||
160 | private onClientRoute (options: RegisterClientRouteOptions) { | ||
161 | const route = options.route.startsWith('/') | ||
162 | ? options.route | ||
163 | : `/${options.route}` | ||
164 | |||
165 | this.clientRoutes[route] = options | ||
166 | } | ||
167 | |||
149 | private buildPeerTubeHelpers (pluginInfo: PluginInfo): RegisterClientHelpers { | 168 | private buildPeerTubeHelpers (pluginInfo: PluginInfo): RegisterClientHelpers { |
150 | const { plugin } = pluginInfo | 169 | const { plugin } = pluginInfo |
151 | const npmName = this.nameToNpmName(pluginInfo.plugin.name, pluginInfo.pluginType) | 170 | const npmName = this.nameToNpmName(pluginInfo.plugin.name, pluginInfo.pluginType) |
@@ -161,6 +180,10 @@ export class PluginService implements ClientHook { | |||
161 | return environment.apiUrl + `${pathPrefix}/${plugin.name}/${plugin.version}/router` | 180 | return environment.apiUrl + `${pathPrefix}/${plugin.name}/${plugin.version}/router` |
162 | }, | 181 | }, |
163 | 182 | ||
183 | getBasePluginClientPath: () => { | ||
184 | return '/p' | ||
185 | }, | ||
186 | |||
164 | getSettings: () => { | 187 | getSettings: () => { |
165 | const path = PluginService.BASE_PLUGIN_API_URL + '/' + npmName + '/public-settings' | 188 | const path = PluginService.BASE_PLUGIN_API_URL + '/' + npmName + '/public-settings' |
166 | 189 | ||