aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-08-02 15:29:00 +0200
committerChocobozzz <me@florianbigard.com>2022-08-02 15:50:05 +0200
commit22df69fdecf299c8be6acaa25f086249ea9a0085 (patch)
treee8c7e21c18fb42bb74b54f2eab1509c3d93a380d /shared
parent7a9e420a02434e4f16c99e7d58da9075dff25d15 (diff)
downloadPeerTube-22df69fdecf299c8be6acaa25f086249ea9a0085.tar.gz
PeerTube-22df69fdecf299c8be6acaa25f086249ea9a0085.tar.zst
PeerTube-22df69fdecf299c8be6acaa25f086249ea9a0085.zip
Add job queue hooks
Diffstat (limited to 'shared')
-rw-r--r--shared/core-utils/plugins/hooks.ts17
-rw-r--r--shared/models/plugins/server/server-hook.model.ts5
2 files changed, 17 insertions, 5 deletions
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) {
8 return HookType.STATIC 8 return HookType.STATIC
9} 9}
10 10
11async function internalRunHook <T> (handler: Function, hookType: HookType, result: T, params: any, onError: (err: Error) => void) { 11async function internalRunHook <T> (options: {
12 handler: Function
13 hookType: HookType
14 result: T
15 params: any
16 onError: (err: Error) => void
17}) {
18 const { handler, hookType, result, params, onError } = options
19
12 try { 20 try {
13 if (hookType === HookType.FILTER) { 21 if (hookType === HookType.FILTER) {
14 const p = handler(result, params) 22 const p = handler(result, params)
15 23
16 if (isPromise(p)) result = await p 24 const newResult = isPromise(p)
17 else result = p 25 ? await p
26 : p
18 27
19 return result 28 return newResult
20 } 29 }
21 30
22 // Action/static hooks do not have result value 31 // 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 = {
90 90
91 // Filter result to check if the embed is allowed for a particular request 91 // Filter result to check if the embed is allowed for a particular request
92 'filter:html.embed.video.allowed.result': true, 92 'filter:html.embed.video.allowed.result': true,
93 'filter:html.embed.video-playlist.allowed.result': true 93 'filter:html.embed.video-playlist.allowed.result': true,
94
95 'filter:job-queue.process.params': true,
96 'filter:job-queue.process.result': true
94} 97}
95 98
96export type ServerFilterHookName = keyof typeof serverFilterHookObject 99export type ServerFilterHookName = keyof typeof serverFilterHookObject