From 22df69fdecf299c8be6acaa25f086249ea9a0085 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 2 Aug 2022 15:29:00 +0200 Subject: Add job queue hooks --- shared/core-utils/plugins/hooks.ts | 17 +++++++++++++---- shared/models/plugins/server/server-hook.model.ts | 5 ++++- 2 files changed, 17 insertions(+), 5 deletions(-) (limited to 'shared') diff --git a/shared/core-utils/plugins/hooks.ts b/shared/core-utils/plugins/hooks.ts index 92cb5ad68..3784969b5 100644 --- a/shared/core-utils/plugins/hooks.ts +++ b/shared/core-utils/plugins/hooks.ts @@ -8,15 +8,24 @@ function getHookType (hookName: string) { return HookType.STATIC } -async function internalRunHook (handler: Function, hookType: HookType, result: T, params: any, onError: (err: Error) => void) { +async function internalRunHook (options: { + handler: Function + hookType: HookType + result: T + params: any + onError: (err: Error) => void +}) { + const { handler, hookType, result, params, onError } = options + try { if (hookType === HookType.FILTER) { const p = handler(result, params) - if (isPromise(p)) result = await p - else result = p + const newResult = isPromise(p) + ? await p + : p - return result + return newResult } // Action/static hooks do not have result value diff --git a/shared/models/plugins/server/server-hook.model.ts b/shared/models/plugins/server/server-hook.model.ts index e64c3bbbc..a8e31f576 100644 --- a/shared/models/plugins/server/server-hook.model.ts +++ b/shared/models/plugins/server/server-hook.model.ts @@ -90,7 +90,10 @@ export const serverFilterHookObject = { // Filter result to check if the embed is allowed for a particular request 'filter:html.embed.video.allowed.result': true, - 'filter:html.embed.video-playlist.allowed.result': true + 'filter:html.embed.video-playlist.allowed.result': true, + + 'filter:job-queue.process.params': true, + 'filter:job-queue.process.result': true } export type ServerFilterHookName = keyof typeof serverFilterHookObject -- cgit v1.2.3