diff options
Diffstat (limited to 'server/lib/plugins')
-rw-r--r-- | server/lib/plugins/hooks.ts | 4 | ||||
-rw-r--r-- | server/lib/plugins/plugin-helpers-builder.ts | 4 | ||||
-rw-r--r-- | server/lib/plugins/plugin-manager.ts | 8 |
3 files changed, 12 insertions, 4 deletions
diff --git a/server/lib/plugins/hooks.ts b/server/lib/plugins/hooks.ts index 327aaece2..694527c12 100644 --- a/server/lib/plugins/hooks.ts +++ b/server/lib/plugins/hooks.ts | |||
@@ -8,8 +8,8 @@ type RawFunction <U, T> = (params: U) => T | |||
8 | 8 | ||
9 | // Helpers to run hooks | 9 | // Helpers to run hooks |
10 | const Hooks = { | 10 | const Hooks = { |
11 | wrapObject: <T, U extends ServerFilterHookName>(result: T, hookName: U) => { | 11 | wrapObject: <T, U extends ServerFilterHookName>(result: T, hookName: U, context?: any) => { |
12 | return PluginManager.Instance.runHook(hookName, result) | 12 | return PluginManager.Instance.runHook(hookName, result, context) |
13 | }, | 13 | }, |
14 | 14 | ||
15 | wrapPromiseFun: async <U, T, V extends ServerFilterHookName>(fun: PromiseFunction<U, T>, params: U, hookName: V) => { | 15 | wrapPromiseFun: async <U, T, V extends ServerFilterHookName>(fun: PromiseFunction<U, T>, params: U, hookName: V) => { |
diff --git a/server/lib/plugins/plugin-helpers-builder.ts b/server/lib/plugins/plugin-helpers-builder.ts index b76c0a8a4..4e799b3d4 100644 --- a/server/lib/plugins/plugin-helpers-builder.ts +++ b/server/lib/plugins/plugin-helpers-builder.ts | |||
@@ -220,6 +220,10 @@ function buildPluginRelatedHelpers (plugin: MPlugin, npmName: string) { | |||
220 | 220 | ||
221 | function buildUserHelpers () { | 221 | function buildUserHelpers () { |
222 | return { | 222 | return { |
223 | loadById: (id: number) => { | ||
224 | return UserModel.loadByIdFull(id) | ||
225 | }, | ||
226 | |||
223 | getAuthUser: (res: express.Response) => { | 227 | getAuthUser: (res: express.Response) => { |
224 | const user = res.locals.oauth?.token?.User | 228 | const user = res.locals.oauth?.token?.User |
225 | if (!user) return undefined | 229 | if (!user) return undefined |
diff --git a/server/lib/plugins/plugin-manager.ts b/server/lib/plugins/plugin-manager.ts index c21ebd0c5..a706df1e0 100644 --- a/server/lib/plugins/plugin-manager.ts +++ b/server/lib/plugins/plugin-manager.ts | |||
@@ -215,8 +215,12 @@ export class PluginManager implements ServerHook { | |||
215 | for (const hook of this.hooks[hookName]) { | 215 | for (const hook of this.hooks[hookName]) { |
216 | logger.debug('Running hook %s of plugin %s.', hookName, hook.npmName) | 216 | logger.debug('Running hook %s of plugin %s.', hookName, hook.npmName) |
217 | 217 | ||
218 | result = await internalRunHook(hook.handler, hookType, result, params, err => { | 218 | result = await internalRunHook({ |
219 | logger.error('Cannot run hook %s of plugin %s.', hookName, hook.pluginName, { err }) | 219 | handler: hook.handler, |
220 | hookType, | ||
221 | result, | ||
222 | params, | ||
223 | onError: err => { logger.error('Cannot run hook %s of plugin %s.', hookName, hook.pluginName, { err }) } | ||
220 | }) | 224 | }) |
221 | } | 225 | } |
222 | 226 | ||