diff options
author | Chocobozzz <me@florianbigard.com> | 2020-04-30 09:28:39 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-05-04 16:21:39 +0200 |
commit | a5896799f169d3313b63165fe6a79d4149fa6df1 (patch) | |
tree | 0151902e829dce13bbb22ff0fe6967ce6bee4058 /server/lib/plugins/plugin-manager.ts | |
parent | dadc90bca257f2d785713a37949c3a1bf6a5243d (diff) | |
download | PeerTube-a5896799f169d3313b63165fe6a79d4149fa6df1.tar.gz PeerTube-a5896799f169d3313b63165fe6a79d4149fa6df1.tar.zst PeerTube-a5896799f169d3313b63165fe6a79d4149fa6df1.zip |
Add plugin settings change watcher
Diffstat (limited to 'server/lib/plugins/plugin-manager.ts')
-rw-r--r-- | server/lib/plugins/plugin-manager.ts | 45 |
1 files changed, 31 insertions, 14 deletions
diff --git a/server/lib/plugins/plugin-manager.ts b/server/lib/plugins/plugin-manager.ts index f7b84b1ff..950acf7ad 100644 --- a/server/lib/plugins/plugin-manager.ts +++ b/server/lib/plugins/plugin-manager.ts | |||
@@ -144,20 +144,6 @@ export class PluginManager implements ServerHook { | |||
144 | return this.translations[locale] || {} | 144 | return this.translations[locale] || {} |
145 | } | 145 | } |
146 | 146 | ||
147 | onLogout (npmName: string, authName: string, user: MUser) { | ||
148 | const auth = this.getAuth(npmName, authName) | ||
149 | |||
150 | if (auth?.onLogout) { | ||
151 | logger.info('Running onLogout function from auth %s of plugin %s', authName, npmName) | ||
152 | |||
153 | try { | ||
154 | auth.onLogout(user) | ||
155 | } catch (err) { | ||
156 | logger.warn('Cannot run onLogout function from auth %s of plugin %s.', authName, npmName, { err }) | ||
157 | } | ||
158 | } | ||
159 | } | ||
160 | |||
161 | async isTokenValid (token: MOAuthTokenUser, type: 'access' | 'refresh') { | 147 | async isTokenValid (token: MOAuthTokenUser, type: 'access' | 'refresh') { |
162 | const auth = this.getAuth(token.User.pluginAuth, token.authName) | 148 | const auth = this.getAuth(token.User.pluginAuth, token.authName) |
163 | if (!auth) return true | 149 | if (!auth) return true |
@@ -180,6 +166,37 @@ export class PluginManager implements ServerHook { | |||
180 | return true | 166 | return true |
181 | } | 167 | } |
182 | 168 | ||
169 | // ###################### External events ###################### | ||
170 | |||
171 | onLogout (npmName: string, authName: string, user: MUser) { | ||
172 | const auth = this.getAuth(npmName, authName) | ||
173 | |||
174 | if (auth?.onLogout) { | ||
175 | logger.info('Running onLogout function from auth %s of plugin %s', authName, npmName) | ||
176 | |||
177 | try { | ||
178 | auth.onLogout(user) | ||
179 | } catch (err) { | ||
180 | logger.warn('Cannot run onLogout function from auth %s of plugin %s.', authName, npmName, { err }) | ||
181 | } | ||
182 | } | ||
183 | } | ||
184 | |||
185 | onSettingsChanged (name: string, settings: any) { | ||
186 | const registered = this.getRegisteredPluginByShortName(name) | ||
187 | if (!registered) { | ||
188 | logger.error('Cannot find plugin %s to call on settings changed.', name) | ||
189 | } | ||
190 | |||
191 | for (const cb of registered.registerHelpersStore.getOnSettingsChangedCallbacks()) { | ||
192 | try { | ||
193 | cb(settings) | ||
194 | } catch (err) { | ||
195 | logger.error('Cannot run on settings changed callback for %s.', registered.npmName, { err }) | ||
196 | } | ||
197 | } | ||
198 | } | ||
199 | |||
183 | // ###################### Hooks ###################### | 200 | // ###################### Hooks ###################### |
184 | 201 | ||
185 | async runHook<T> (hookName: ServerHookName, result?: T, params?: any): Promise<T> { | 202 | async runHook<T> (hookName: ServerHookName, result?: T, params?: any): Promise<T> { |