aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/plugins/plugin-manager.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/plugins/plugin-manager.ts')
-rw-r--r--server/lib/plugins/plugin-manager.ts22
1 files changed, 9 insertions, 13 deletions
diff --git a/server/lib/plugins/plugin-manager.ts b/server/lib/plugins/plugin-manager.ts
index 570b56193..85ee3decb 100644
--- a/server/lib/plugins/plugin-manager.ts
+++ b/server/lib/plugins/plugin-manager.ts
@@ -14,6 +14,10 @@ import { RegisterSettingOptions } from '../../../shared/models/plugins/register-
14import { RegisterHookOptions } from '../../../shared/models/plugins/register-hook.model' 14import { RegisterHookOptions } from '../../../shared/models/plugins/register-hook.model'
15import { PluginSettingsManager } from '../../../shared/models/plugins/plugin-settings-manager.model' 15import { PluginSettingsManager } from '../../../shared/models/plugins/plugin-settings-manager.model'
16import { PluginStorageManager } from '../../../shared/models/plugins/plugin-storage-manager.model' 16import { PluginStorageManager } from '../../../shared/models/plugins/plugin-storage-manager.model'
17import { ServerHookName, ServerHook } from '../../../shared/models/plugins/server-hook.model'
18import { isCatchable, isPromise } from '../../../shared/core-utils/miscs/miscs'
19import { getHookType, internalRunHook } from '../../../shared/core-utils/plugins/hooks'
20import { HookType } from '../../../shared/models/plugins/hook-type.enum'
17 21
18export interface RegisteredPlugin { 22export interface RegisteredPlugin {
19 npmName: string 23 npmName: string
@@ -42,7 +46,7 @@ export interface HookInformationValue {
42 priority: number 46 priority: number
43} 47}
44 48
45export class PluginManager { 49export class PluginManager implements ServerHook {
46 50
47 private static instance: PluginManager 51 private static instance: PluginManager
48 52
@@ -95,25 +99,17 @@ export class PluginManager {
95 99
96 // ###################### Hooks ###################### 100 // ###################### Hooks ######################
97 101
98 async runHook (hookName: string, param?: any) { 102 async runHook (hookName: ServerHookName, param?: any) {
99 let result = param 103 let result = param
100 104
101 if (!this.hooks[hookName]) return result 105 if (!this.hooks[hookName]) return result
102 106
103 const wait = hookName.startsWith('static:') 107 const hookType = getHookType(hookName)
104 108
105 for (const hook of this.hooks[hookName]) { 109 for (const hook of this.hooks[hookName]) {
106 try { 110 result = await internalRunHook(hook.handler, hookType, param, err => {
107 const p = hook.handler(param)
108
109 if (wait) {
110 result = await p
111 } else if (p.catch) {
112 p.catch(err => logger.warn('Hook %s of plugin %s thrown an error.', hookName, hook.pluginName, { err }))
113 }
114 } catch (err) {
115 logger.error('Cannot run hook %s of plugin %s.', hookName, hook.pluginName, { err }) 111 logger.error('Cannot run hook %s of plugin %s.', hookName, hook.pluginName, { err })
116 } 112 })
117 } 113 }
118 114
119 return result 115 return result