diff options
-rw-r--r-- | server/types/plugins/register-server-option.model.ts | 4 | ||||
-rw-r--r-- | support/doc/plugins/guide.md | 27 |
2 files changed, 30 insertions, 1 deletions
diff --git a/server/types/plugins/register-server-option.model.ts b/server/types/plugins/register-server-option.model.ts index 1b9250ce4..4af476ed2 100644 --- a/server/types/plugins/register-server-option.model.ts +++ b/server/types/plugins/register-server-option.model.ts | |||
@@ -58,14 +58,18 @@ export type PeerTubeHelpers = { | |||
58 | } | 58 | } |
59 | 59 | ||
60 | plugin: { | 60 | plugin: { |
61 | // PeerTube >= 3.2 | ||
61 | getBaseStaticRoute: () => string | 62 | getBaseStaticRoute: () => string |
62 | 63 | ||
64 | // PeerTube >= 3.2 | ||
63 | getBaseRouterRoute: () => string | 65 | getBaseRouterRoute: () => string |
64 | 66 | ||
67 | // PeerTube >= 3.2 | ||
65 | getDataDirectoryPath: () => string | 68 | getDataDirectoryPath: () => string |
66 | } | 69 | } |
67 | 70 | ||
68 | user: { | 71 | user: { |
72 | // PeerTube >= 3.2 | ||
69 | getAuthUser: (response: Response) => { | 73 | getAuthUser: (response: Response) => { |
70 | id?: string | 74 | id?: string |
71 | username: string | 75 | username: string |
diff --git a/support/doc/plugins/guide.md b/support/doc/plugins/guide.md index 36ade117b..a90f8e72b 100644 --- a/support/doc/plugins/guide.md +++ b/support/doc/plugins/guide.md | |||
@@ -20,6 +20,7 @@ | |||
20 | - [Plugin static route](#plugin-static-route) | 20 | - [Plugin static route](#plugin-static-route) |
21 | - [Notifier](#notifier) | 21 | - [Notifier](#notifier) |
22 | - [Markdown Renderer](#markdown-renderer) | 22 | - [Markdown Renderer](#markdown-renderer) |
23 | - [Auth header](#auth-header) | ||
23 | - [Custom Modal](#custom-modal) | 24 | - [Custom Modal](#custom-modal) |
24 | - [Translate](#translate) | 25 | - [Translate](#translate) |
25 | - [Get public settings](#get-public-settings) | 26 | - [Get public settings](#get-public-settings) |
@@ -203,7 +204,7 @@ function register ({ | |||
203 | } | 204 | } |
204 | ``` | 205 | ``` |
205 | 206 | ||
206 | You can also store files in the plugin data directory (`/{plugins-directory}/data/{npm-plugin-name}`). | 207 | You can also store files in the plugin data directory (`/{plugins-directory}/data/{npm-plugin-name}`) **in PeerTube >= 3.2**. |
207 | This directory and its content won't be deleted when your plugin is uninstalled/upgraded. | 208 | This directory and its content won't be deleted when your plugin is uninstalled/upgraded. |
208 | 209 | ||
209 | ```js | 210 | ```js |
@@ -526,6 +527,30 @@ function register (...) { | |||
526 | } | 527 | } |
527 | ``` | 528 | ``` |
528 | 529 | ||
530 | #### Auth header | ||
531 | |||
532 | **PeerTube >= 3.2** | ||
533 | |||
534 | To make your own HTTP requests using the current authenticated user, use an helper to automatically set appropriate headers: | ||
535 | |||
536 | ```js | ||
537 | function register (...) { | ||
538 | registerHook({ | ||
539 | target: 'action:auth-user.information-loaded', | ||
540 | handler: ({ user }) => { | ||
541 | |||
542 | // Useless because we have the same info in the ({ user }) parameter | ||
543 | // It's just an example | ||
544 | fetch('/api/v1/users/me', { | ||
545 | method: 'GET', | ||
546 | headers: peertubeHelpers.getAuthHeader() | ||
547 | }).then(res => res.json()) | ||
548 | .then(data => console.log('Hi %s.', data.username)) | ||
549 | } | ||
550 | }) | ||
551 | } | ||
552 | ``` | ||
553 | |||
529 | #### Custom Modal | 554 | #### Custom Modal |
530 | 555 | ||
531 | To show a custom modal: | 556 | To show a custom modal: |