]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Adding frontend peertubeHelpers.getBaseRouterRoute. (#4153)
authorJohn Livingston <38844060+JohnXLivingston@users.noreply.github.com>
Thu, 3 Jun 2021 10:28:26 +0000 (12:28 +0200)
committerGitHub <noreply@github.com>
Thu, 3 Jun 2021 10:28:26 +0000 (12:28 +0200)
* Adding frontend peertubeHelpers.getBaseRouterRoute.

* Fix doctoc.

client/src/app/core/plugins/plugin.service.ts
client/src/standalone/videos/embed.ts
client/src/types/register-client-option.model.ts
support/doc/plugins/guide.md

index 6a1a46e73c875dfa625aefd9a2f153dd8a3677a7..a3de9839053f3daca18605aa0ae0b17517bcc658 100644 (file)
@@ -250,6 +250,11 @@ export class PluginService implements ClientHook {
         return environment.apiUrl + `${pathPrefix}/${plugin.name}/${plugin.version}/static`
       },
 
+      getBaseRouterRoute: () => {
+        const pathPrefix = this.getPluginPathPrefix(pluginInfo.isTheme)
+        return environment.apiUrl + `${pathPrefix}/${plugin.name}/${plugin.version}/router`
+      },
+
       getSettings: () => {
         const path = PluginService.BASE_PLUGIN_API_URL + '/' + npmName + '/public-settings'
 
index 4ce5c78e8b45a26aae24e7055cd8aae98306bc30..a367feb8e529744ee05f1e618b07a3b86ba0e58a 100644 (file)
@@ -781,6 +781,8 @@ export class PeerTubeEmbed {
     return {
       getBaseStaticRoute: unimplemented,
 
+      getBaseRouterRoute: unimplemented,
+
       getSettings: unimplemented,
 
       isLoggedIn: unimplemented,
index 8802edc3299461fde42baf867a53f45786f16339..59bcbc5ffc79fd9384683631314d5a5d05c50ff3 100644 (file)
@@ -19,6 +19,8 @@ export type RegisterClientOptions = {
 export type RegisterClientHelpers = {
   getBaseStaticRoute: () => string
 
+  getBaseRouterRoute: () => string
+
   isLoggedIn: () => boolean
 
   getAuthHeader: () => { 'Authorization': string } | undefined
index d3b9db0ed0fbf6cd86c1f3fae88b65ba4eb0c1d6..db1f1863cf00df94ce0af123de9c0afc061e01cd 100644 (file)
@@ -21,6 +21,7 @@
     - [Notifier](#notifier)
     - [Markdown Renderer](#markdown-renderer)
     - [Auth header](#auth-header)
+    - [Plugin router route](#plugin-router-route)
     - [Custom Modal](#custom-modal)
     - [Translate](#translate)
     - [Get public settings](#get-public-settings)
@@ -561,6 +562,27 @@ function register (...) {
 }
 ```
 
+#### Plugin router route
+
+**PeerTube >= 3.3**
+
+To get your plugin router route, you can use `peertubeHelpers.getBaseRouterRoute()`:
+
+```js
+function register (...) {
+  registerHook({
+    target: 'action:video-watch.video.loaded',
+    handler: ({ video }) => {
+      fetch(peertubeHelpers.getBaseRouterRoute() + '/my/plugin/api', {
+        method: 'GET',
+        headers: peertubeHelpers.getAuthHeader()
+      }).then(res => res.json())
+        .then(data => console.log('Hi %s.', data))
+    }
+  })
+}
+```
+
 #### Custom Modal
 
 To show a custom modal: