diff options
author | Chocobozzz <me@florianbigard.com> | 2023-03-10 11:10:16 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2023-03-10 15:45:52 +0100 |
commit | 4899138ec5995075c3681ccbd9f6b163fb915991 (patch) | |
tree | 285973833829de6c20a0aeb95142a07e839db29f /client/src/app | |
parent | 085aba61c35ad63155a46453dff7752840e82146 (diff) | |
download | PeerTube-4899138ec5995075c3681ccbd9f6b163fb915991.tar.gz PeerTube-4899138ec5995075c3681ccbd9f6b163fb915991.tar.zst PeerTube-4899138ec5995075c3681ccbd9f6b163fb915991.zip |
Add ability for plugins to add metadata
Diffstat (limited to 'client/src/app')
3 files changed, 46 insertions, 2 deletions
diff --git a/client/src/app/+videos/+video-watch/shared/metadata/video-attributes.component.html b/client/src/app/+videos/+video-watch/shared/metadata/video-attributes.component.html index 52ad1999d..0aa707666 100644 --- a/client/src/app/+videos/+video-watch/shared/metadata/video-attributes.component.html +++ b/client/src/app/+videos/+video-watch/shared/metadata/video-attributes.component.html | |||
@@ -62,3 +62,10 @@ | |||
62 | <span i18n class="attribute-label">Duration</span> | 62 | <span i18n class="attribute-label">Duration</span> |
63 | <span class="attribute-value">{{ video.duration | myDurationFormatter }}</span> | 63 | <span class="attribute-value">{{ video.duration | myDurationFormatter }}</span> |
64 | </div> | 64 | </div> |
65 | |||
66 | <div class="attribute attribute-plugin" *ngFor="let metadata of pluginMetadata"> | ||
67 | <span class="attribute-label">{{ metadata.label }}</span> | ||
68 | |||
69 | <span *ngIf="metadata.value" class="attribute-value">{{ metadata.value }}</span> | ||
70 | <span *ngIf="metadata.safeHTML" class="attribute-value" [innerHTML]="metadata.safeHTML"></span> | ||
71 | </div> | ||
diff --git a/client/src/app/+videos/+video-watch/shared/metadata/video-attributes.component.ts b/client/src/app/+videos/+video-watch/shared/metadata/video-attributes.component.ts index b8f564c4c..ebfb42711 100644 --- a/client/src/app/+videos/+video-watch/shared/metadata/video-attributes.component.ts +++ b/client/src/app/+videos/+video-watch/shared/metadata/video-attributes.component.ts | |||
@@ -1,14 +1,35 @@ | |||
1 | import { Component, Input } from '@angular/core' | 1 | import { Component, Input, OnInit } from '@angular/core' |
2 | import { HooksService } from '@app/core' | ||
2 | import { VideoDetails } from '@app/shared/shared-main' | 3 | import { VideoDetails } from '@app/shared/shared-main' |
3 | 4 | ||
5 | type PluginMetadata = { | ||
6 | label: string | ||
7 | |||
8 | value?: string | ||
9 | safeHTML?: string | ||
10 | } | ||
11 | |||
4 | @Component({ | 12 | @Component({ |
5 | selector: 'my-video-attributes', | 13 | selector: 'my-video-attributes', |
6 | templateUrl: './video-attributes.component.html', | 14 | templateUrl: './video-attributes.component.html', |
7 | styleUrls: [ './video-attributes.component.scss' ] | 15 | styleUrls: [ './video-attributes.component.scss' ] |
8 | }) | 16 | }) |
9 | export class VideoAttributesComponent { | 17 | export class VideoAttributesComponent implements OnInit { |
10 | @Input() video: VideoDetails | 18 | @Input() video: VideoDetails |
11 | 19 | ||
20 | pluginMetadata: PluginMetadata[] = [] | ||
21 | |||
22 | constructor (private hooks: HooksService) { } | ||
23 | |||
24 | async ngOnInit () { | ||
25 | this.pluginMetadata = await this.hooks.wrapFunResult( | ||
26 | this.buildPluginMetadata.bind(this), | ||
27 | { video: this.video }, | ||
28 | 'video-watch', | ||
29 | 'filter:video-watch.video-plugin-metadata.result' | ||
30 | ) | ||
31 | } | ||
32 | |||
12 | getVideoHost () { | 33 | getVideoHost () { |
13 | return this.video.channel.host | 34 | return this.video.channel.host |
14 | } | 35 | } |
@@ -18,4 +39,11 @@ export class VideoAttributesComponent { | |||
18 | 39 | ||
19 | return this.video.tags | 40 | return this.video.tags |
20 | } | 41 | } |
42 | |||
43 | // Used for plugin hooks | ||
44 | private buildPluginMetadata (_options: { | ||
45 | video: VideoDetails | ||
46 | }): PluginMetadata[] { | ||
47 | return [] | ||
48 | } | ||
21 | } | 49 | } |
diff --git a/client/src/app/core/plugins/hooks.service.ts b/client/src/app/core/plugins/hooks.service.ts index 29db75d89..f325605e9 100644 --- a/client/src/app/core/plugins/hooks.service.ts +++ b/client/src/app/core/plugins/hooks.service.ts | |||
@@ -48,6 +48,15 @@ export class HooksService { | |||
48 | return this.pluginService.runHook(hookResultName, result, params) | 48 | return this.pluginService.runHook(hookResultName, result, params) |
49 | } | 49 | } |
50 | 50 | ||
51 | async wrapFunResult <P, R, H extends ClientFilterHookName> | ||
52 | (fun: RawFunction<P, R>, params: P, scope: PluginClientScope, hookResultName: H) { | ||
53 | await this.pluginService.ensurePluginsAreLoaded(scope) | ||
54 | |||
55 | const result = fun(params) | ||
56 | |||
57 | return this.pluginService.runHook(hookResultName, result, params) | ||
58 | } | ||
59 | |||
51 | runAction<T, U extends ClientActionHookName> (hookName: U, scope: PluginClientScope, params?: T) { | 60 | runAction<T, U extends ClientActionHookName> (hookName: U, scope: PluginClientScope, params?: T) { |
52 | // Use setTimeout to give priority to Angular change detector | 61 | // Use setTimeout to give priority to Angular change detector |
53 | setTimeout(() => { | 62 | setTimeout(() => { |