aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/plugins/hooks.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-07-18 14:28:37 +0200
committerChocobozzz <chocobozzz@cpy.re>2019-07-24 10:58:16 +0200
commitb4055e1c23eeefb0c8a85a77f312b2827d98f483 (patch)
tree51b6b04c1ad10897047817d2eaaa037d1331fa6a /server/lib/plugins/hooks.ts
parent66e001c848c009412c65cbce41be344d8985fd83 (diff)
downloadPeerTube-b4055e1c23eeefb0c8a85a77f312b2827d98f483.tar.gz
PeerTube-b4055e1c23eeefb0c8a85a77f312b2827d98f483.tar.zst
PeerTube-b4055e1c23eeefb0c8a85a77f312b2827d98f483.zip
Add server hooks
Diffstat (limited to 'server/lib/plugins/hooks.ts')
-rw-r--r--server/lib/plugins/hooks.ts26
1 files changed, 26 insertions, 0 deletions
diff --git a/server/lib/plugins/hooks.ts b/server/lib/plugins/hooks.ts
new file mode 100644
index 000000000..7bb907e6a
--- /dev/null
+++ b/server/lib/plugins/hooks.ts
@@ -0,0 +1,26 @@
1import { ServerActionHookName, ServerFilterHookName } from '../../../shared/models/plugins/server-hook.model'
2import { PluginManager } from './plugin-manager'
3import { logger } from '../../helpers/logger'
4import * as Bluebird from 'bluebird'
5
6// Helpers to run hooks
7const Hooks = {
8 wrapObject: <T, U extends ServerFilterHookName>(obj: T, hookName: U) => {
9 return PluginManager.Instance.runHook(hookName, obj) as Promise<T>
10 },
11
12 wrapPromise: async <T, U extends ServerFilterHookName>(fun: Promise<T> | Bluebird<T>, hookName: U) => {
13 const result = await fun
14
15 return PluginManager.Instance.runHook(hookName, result)
16 },
17
18 runAction: <T, U extends ServerActionHookName>(hookName: U, params?: T) => {
19 PluginManager.Instance.runHook(hookName, params)
20 .catch(err => logger.error('Fatal hook error.', { err }))
21 }
22}
23
24export {
25 Hooks
26}