aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJohn Livingston <38844060+JohnXLivingston@users.noreply.github.com>2021-06-03 12:28:26 +0200
committerGitHub <noreply@github.com>2021-06-03 12:28:26 +0200
commit9777fe9eebe53debdf45091cab98f72a5987e05a (patch)
tree0f85ae9dc3ef89e0ca111d21e4a48d942ff3f991
parent63da15eb18065ef6c419f073c95fec6ef5541652 (diff)
downloadPeerTube-9777fe9eebe53debdf45091cab98f72a5987e05a.tar.gz
PeerTube-9777fe9eebe53debdf45091cab98f72a5987e05a.tar.zst
PeerTube-9777fe9eebe53debdf45091cab98f72a5987e05a.zip
Adding frontend peertubeHelpers.getBaseRouterRoute. (#4153)
* Adding frontend peertubeHelpers.getBaseRouterRoute. * Fix doctoc.
-rw-r--r--client/src/app/core/plugins/plugin.service.ts5
-rw-r--r--client/src/standalone/videos/embed.ts2
-rw-r--r--client/src/types/register-client-option.model.ts2
-rw-r--r--support/doc/plugins/guide.md22
4 files changed, 31 insertions, 0 deletions
diff --git a/client/src/app/core/plugins/plugin.service.ts b/client/src/app/core/plugins/plugin.service.ts
index 6a1a46e73..a3de98390 100644
--- a/client/src/app/core/plugins/plugin.service.ts
+++ b/client/src/app/core/plugins/plugin.service.ts
@@ -250,6 +250,11 @@ export class PluginService implements ClientHook {
250 return environment.apiUrl + `${pathPrefix}/${plugin.name}/${plugin.version}/static` 250 return environment.apiUrl + `${pathPrefix}/${plugin.name}/${plugin.version}/static`
251 }, 251 },
252 252
253 getBaseRouterRoute: () => {
254 const pathPrefix = this.getPluginPathPrefix(pluginInfo.isTheme)
255 return environment.apiUrl + `${pathPrefix}/${plugin.name}/${plugin.version}/router`
256 },
257
253 getSettings: () => { 258 getSettings: () => {
254 const path = PluginService.BASE_PLUGIN_API_URL + '/' + npmName + '/public-settings' 259 const path = PluginService.BASE_PLUGIN_API_URL + '/' + npmName + '/public-settings'
255 260
diff --git a/client/src/standalone/videos/embed.ts b/client/src/standalone/videos/embed.ts
index 4ce5c78e8..a367feb8e 100644
--- a/client/src/standalone/videos/embed.ts
+++ b/client/src/standalone/videos/embed.ts
@@ -781,6 +781,8 @@ export class PeerTubeEmbed {
781 return { 781 return {
782 getBaseStaticRoute: unimplemented, 782 getBaseStaticRoute: unimplemented,
783 783
784 getBaseRouterRoute: unimplemented,
785
784 getSettings: unimplemented, 786 getSettings: unimplemented,
785 787
786 isLoggedIn: unimplemented, 788 isLoggedIn: unimplemented,
diff --git a/client/src/types/register-client-option.model.ts b/client/src/types/register-client-option.model.ts
index 8802edc32..59bcbc5ff 100644
--- a/client/src/types/register-client-option.model.ts
+++ b/client/src/types/register-client-option.model.ts
@@ -19,6 +19,8 @@ export type RegisterClientOptions = {
19export type RegisterClientHelpers = { 19export type RegisterClientHelpers = {
20 getBaseStaticRoute: () => string 20 getBaseStaticRoute: () => string
21 21
22 getBaseRouterRoute: () => string
23
22 isLoggedIn: () => boolean 24 isLoggedIn: () => boolean
23 25
24 getAuthHeader: () => { 'Authorization': string } | undefined 26 getAuthHeader: () => { 'Authorization': string } | undefined
diff --git a/support/doc/plugins/guide.md b/support/doc/plugins/guide.md
index d3b9db0ed..db1f1863c 100644
--- a/support/doc/plugins/guide.md
+++ b/support/doc/plugins/guide.md
@@ -21,6 +21,7 @@
21 - [Notifier](#notifier) 21 - [Notifier](#notifier)
22 - [Markdown Renderer](#markdown-renderer) 22 - [Markdown Renderer](#markdown-renderer)
23 - [Auth header](#auth-header) 23 - [Auth header](#auth-header)
24 - [Plugin router route](#plugin-router-route)
24 - [Custom Modal](#custom-modal) 25 - [Custom Modal](#custom-modal)
25 - [Translate](#translate) 26 - [Translate](#translate)
26 - [Get public settings](#get-public-settings) 27 - [Get public settings](#get-public-settings)
@@ -561,6 +562,27 @@ function register (...) {
561} 562}
562``` 563```
563 564
565#### Plugin router route
566
567**PeerTube >= 3.3**
568
569To get your plugin router route, you can use `peertubeHelpers.getBaseRouterRoute()`:
570
571```js
572function register (...) {
573 registerHook({
574 target: 'action:video-watch.video.loaded',
575 handler: ({ video }) => {
576 fetch(peertubeHelpers.getBaseRouterRoute() + '/my/plugin/api', {
577 method: 'GET',
578 headers: peertubeHelpers.getAuthHeader()
579 }).then(res => res.json())
580 .then(data => console.log('Hi %s.', data))
581 }
582 })
583}
584```
585
564#### Custom Modal 586#### Custom Modal
565 587
566To show a custom modal: 588To show a custom modal: