ニジカ投稿局 https://tv.nizika.tv
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

36 lines
1.2 KiB

  1. import Bluebird from 'bluebird'
  2. import { ServerActionHookName, ServerFilterHookName } from '@peertube/peertube-models'
  3. import { logger } from '../../helpers/logger.js'
  4. import { PluginManager } from './plugin-manager.js'
  5. type PromiseFunction <U, T> = (params: U) => Promise<T> | Bluebird<T>
  6. type RawFunction <U, T> = (params: U) => T
  7. // Helpers to run hooks
  8. const Hooks = {
  9. wrapObject: <T, U extends ServerFilterHookName>(result: T, hookName: U, context?: any) => {
  10. return PluginManager.Instance.runHook(hookName, result, context)
  11. },
  12. wrapPromiseFun: async <U, T, V extends ServerFilterHookName>(fun: PromiseFunction<U, T>, params: U, hookName: V) => {
  13. const result = await fun(params)
  14. return PluginManager.Instance.runHook(hookName, result, params)
  15. },
  16. wrapFun: async <U, T, V extends ServerFilterHookName>(fun: RawFunction<U, T>, params: U, hookName: V) => {
  17. const result = fun(params)
  18. return PluginManager.Instance.runHook(hookName, result, params)
  19. },
  20. runAction: <T, U extends ServerActionHookName>(hookName: U, params?: T) => {
  21. PluginManager.Instance.runHook(hookName, undefined, params)
  22. .catch(err => logger.error('Fatal hook error.', { err }))
  23. }
  24. }
  25. export {
  26. Hooks
  27. }