From 866b5d3f5230204d611a556260102996c1aefe10 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 10 Mar 2023 12:01:21 +0100 Subject: Add ability for plugins to alter video jsonld --- .../shared/metadata/video-attributes.component.ts | 15 ++++----------- client/src/app/core/plugins/hooks.service.ts | 17 ++++------------- 2 files changed, 8 insertions(+), 24 deletions(-) (limited to 'client/src/app') 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 ebfb42711..1834f7be5 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 @@ -22,11 +22,11 @@ export class VideoAttributesComponent implements OnInit { constructor (private hooks: HooksService) { } async ngOnInit () { - this.pluginMetadata = await this.hooks.wrapFunResult( - this.buildPluginMetadata.bind(this), - { video: this.video }, + this.pluginMetadata = await this.hooks.wrapObject( + this.pluginMetadata, 'video-watch', - 'filter:video-watch.video-plugin-metadata.result' + 'filter:video-watch.video-plugin-metadata.result', + { video: this.video } ) } @@ -39,11 +39,4 @@ export class VideoAttributesComponent implements OnInit { return this.video.tags } - - // Used for plugin hooks - private buildPluginMetadata (_options: { - video: VideoDetails - }): PluginMetadata[] { - return [] - } } diff --git a/client/src/app/core/plugins/hooks.service.ts b/client/src/app/core/plugins/hooks.service.ts index f325605e9..d9fef8389 100644 --- a/client/src/app/core/plugins/hooks.service.ts +++ b/client/src/app/core/plugins/hooks.service.ts @@ -48,15 +48,6 @@ export class HooksService { return this.pluginService.runHook(hookResultName, result, params) } - async wrapFunResult - (fun: RawFunction, params: P, scope: PluginClientScope, hookResultName: H) { - await this.pluginService.ensurePluginsAreLoaded(scope) - - const result = fun(params) - - return this.pluginService.runHook(hookResultName, result, params) - } - runAction (hookName: U, scope: PluginClientScope, params?: T) { // Use setTimeout to give priority to Angular change detector setTimeout(() => { @@ -66,13 +57,13 @@ export class HooksService { }) } - async wrapObject (result: T, scope: PluginClientScope, hookName: U) { + async wrapObject (result: T, scope: PluginClientScope, hookName: U, context?: any) { await this.pluginService.ensurePluginsAreLoaded(scope) - return this.wrapObjectWithoutScopeLoad(result, hookName) + return this.wrapObjectWithoutScopeLoad(result, hookName, context) } - private wrapObjectWithoutScopeLoad (result: T, hookName: U) { - return this.pluginService.runHook(hookName, result) + private wrapObjectWithoutScopeLoad (result: T, hookName: U, context?: any) { + return this.pluginService.runHook(hookName, result, context) } } -- cgit v1.2.3