mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-04 18:29:27 +02:00
Add plugin settings change watcher
This commit is contained in:
parent
dadc90bca2
commit
a5896799f1
9 changed files with 59 additions and 23 deletions
|
@ -144,20 +144,6 @@ export class PluginManager implements ServerHook {
|
|||
return this.translations[locale] || {}
|
||||
}
|
||||
|
||||
onLogout (npmName: string, authName: string, user: MUser) {
|
||||
const auth = this.getAuth(npmName, authName)
|
||||
|
||||
if (auth?.onLogout) {
|
||||
logger.info('Running onLogout function from auth %s of plugin %s', authName, npmName)
|
||||
|
||||
try {
|
||||
auth.onLogout(user)
|
||||
} catch (err) {
|
||||
logger.warn('Cannot run onLogout function from auth %s of plugin %s.', authName, npmName, { err })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async isTokenValid (token: MOAuthTokenUser, type: 'access' | 'refresh') {
|
||||
const auth = this.getAuth(token.User.pluginAuth, token.authName)
|
||||
if (!auth) return true
|
||||
|
@ -180,6 +166,37 @@ export class PluginManager implements ServerHook {
|
|||
return true
|
||||
}
|
||||
|
||||
// ###################### External events ######################
|
||||
|
||||
onLogout (npmName: string, authName: string, user: MUser) {
|
||||
const auth = this.getAuth(npmName, authName)
|
||||
|
||||
if (auth?.onLogout) {
|
||||
logger.info('Running onLogout function from auth %s of plugin %s', authName, npmName)
|
||||
|
||||
try {
|
||||
auth.onLogout(user)
|
||||
} catch (err) {
|
||||
logger.warn('Cannot run onLogout function from auth %s of plugin %s.', authName, npmName, { err })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onSettingsChanged (name: string, settings: any) {
|
||||
const registered = this.getRegisteredPluginByShortName(name)
|
||||
if (!registered) {
|
||||
logger.error('Cannot find plugin %s to call on settings changed.', name)
|
||||
}
|
||||
|
||||
for (const cb of registered.registerHelpersStore.getOnSettingsChangedCallbacks()) {
|
||||
try {
|
||||
cb(settings)
|
||||
} catch (err) {
|
||||
logger.error('Cannot run on settings changed callback for %s.', registered.npmName, { err })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ###################### Hooks ######################
|
||||
|
||||
async runHook<T> (hookName: ServerHookName, result?: T, params?: any): Promise<T> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue