Add ability for plugins to add metadata

pull/5692/head
Chocobozzz 2023-03-10 11:10:16 +01:00
parent 085aba61c3
commit 4899138ec5
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
4 changed files with 48 additions and 2 deletions

View File

@ -62,3 +62,10 @@
<span i18n class="attribute-label">Duration</span>
<span class="attribute-value">{{ video.duration | myDurationFormatter }}</span>
</div>
<div class="attribute attribute-plugin" *ngFor="let metadata of pluginMetadata">
<span class="attribute-label">{{ metadata.label }}</span>
<span *ngIf="metadata.value" class="attribute-value">{{ metadata.value }}</span>
<span *ngIf="metadata.safeHTML" class="attribute-value" [innerHTML]="metadata.safeHTML"></span>
</div>

View File

@ -1,14 +1,35 @@
import { Component, Input } from '@angular/core'
import { Component, Input, OnInit } from '@angular/core'
import { HooksService } from '@app/core'
import { VideoDetails } from '@app/shared/shared-main'
type PluginMetadata = {
label: string
value?: string
safeHTML?: string
}
@Component({
selector: 'my-video-attributes',
templateUrl: './video-attributes.component.html',
styleUrls: [ './video-attributes.component.scss' ]
})
export class VideoAttributesComponent {
export class VideoAttributesComponent implements OnInit {
@Input() video: VideoDetails
pluginMetadata: PluginMetadata[] = []
constructor (private hooks: HooksService) { }
async ngOnInit () {
this.pluginMetadata = await this.hooks.wrapFunResult(
this.buildPluginMetadata.bind(this),
{ video: this.video },
'video-watch',
'filter:video-watch.video-plugin-metadata.result'
)
}
getVideoHost () {
return this.video.channel.host
}
@ -18,4 +39,11 @@ export class VideoAttributesComponent {
return this.video.tags
}
// Used for plugin hooks
private buildPluginMetadata (_options: {
video: VideoDetails
}): PluginMetadata[] {
return []
}
}

View File

@ -48,6 +48,15 @@ export class HooksService {
return this.pluginService.runHook(hookResultName, result, params)
}
async wrapFunResult <P, R, H extends ClientFilterHookName>
(fun: RawFunction<P, R>, params: P, scope: PluginClientScope, hookResultName: H) {
await this.pluginService.ensurePluginsAreLoaded(scope)
const result = fun(params)
return this.pluginService.runHook(hookResultName, result, params)
}
runAction<T, U extends ClientActionHookName> (hookName: U, scope: PluginClientScope, params?: T) {
// Use setTimeout to give priority to Angular change detector
setTimeout(() => {

View File

@ -87,6 +87,8 @@ export const clientFilterHookObject = {
'filter:share.video-playlist-url.build.params': true,
'filter:share.video-playlist-url.build.result': true,
'filter:video-watch.video-plugin-metadata.result': true,
// Filter videojs options built for PeerTube player
'filter:internal.player.videojs.options.result': true,