From 93cae47925e4dd68b7d34a41927b2740b4fab1b4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 22 Jul 2019 15:40:13 +0200 Subject: Add client hooks --- shared/core-utils/plugins/hooks.ts | 2 +- shared/models/plugins/client-hook.model.ts | 39 +++++++++++++++++++++++ shared/models/plugins/plugin-client-scope.type.ts | 1 + shared/models/plugins/plugin-scope.type.ts | 1 - shared/models/plugins/server-hook.model.ts | 2 +- shared/models/server/server-config.model.ts | 3 +- 6 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 shared/models/plugins/client-hook.model.ts create mode 100644 shared/models/plugins/plugin-client-scope.type.ts delete mode 100644 shared/models/plugins/plugin-scope.type.ts (limited to 'shared') diff --git a/shared/core-utils/plugins/hooks.ts b/shared/core-utils/plugins/hooks.ts index 3d59a7428..5405e0529 100644 --- a/shared/core-utils/plugins/hooks.ts +++ b/shared/core-utils/plugins/hooks.ts @@ -29,7 +29,7 @@ async function internalRunHook (handler: Function, hookType: HookType, resul } if (hookType === HookType.ACTION) { - if (isCatchable(p)) p.catch(err => onError(err)) + if (isCatchable(p)) p.catch((err: any) => onError(err)) return undefined } diff --git a/shared/models/plugins/client-hook.model.ts b/shared/models/plugins/client-hook.model.ts new file mode 100644 index 000000000..89400003e --- /dev/null +++ b/shared/models/plugins/client-hook.model.ts @@ -0,0 +1,39 @@ +export type ClientFilterHookName = + 'filter:api.videos.list.trending.params' | + 'filter:api.videos.list.trending.result' | + + 'filter:api.videos.list.local.params' | + 'filter:api.videos.list.local.result' | + + 'filter:api.videos.list.recently-added.params' | + 'filter:api.videos.list.recently-added.result' | + + 'filter:api.videos.list.user-subscriptions.params' | + 'filter:api.videos.list.user-subscriptions.result' | + + 'filter:api.video-watch.video.get.params' | + 'filter:api.video-watch.video.get.result' | + + 'filter:api.video-watch.video-threads.list.params' | + 'filter:api.video-watch.video-threads.list.result' | + + 'filter:api.video-watch.video-thread-replies.list.params' | + 'filter:api.video-watch.video-thread-replies.list.result' | + + 'filter:api.search.videos.list.params' | + 'filter:api.search.videos.list.result' | + 'filter:api.search.video-channels.list.params' | + 'filter:api.search.video-channels.list.result' + +export type ClientActionHookName = + 'action:application.init' | + + 'action:video-watch.init' | + + 'action:video-watch.video.loaded' + +export type ClientHookName = ClientActionHookName | ClientFilterHookName + +export interface ClientHook { + runHook (hookName: ClientHookName, result?: T, params?: any): Promise +} diff --git a/shared/models/plugins/plugin-client-scope.type.ts b/shared/models/plugins/plugin-client-scope.type.ts new file mode 100644 index 000000000..a2112eed7 --- /dev/null +++ b/shared/models/plugins/plugin-client-scope.type.ts @@ -0,0 +1 @@ +export type PluginClientScope = 'common' | 'video-watch' diff --git a/shared/models/plugins/plugin-scope.type.ts b/shared/models/plugins/plugin-scope.type.ts deleted file mode 100644 index b63ae43ec..000000000 --- a/shared/models/plugins/plugin-scope.type.ts +++ /dev/null @@ -1 +0,0 @@ -export type PluginScope = 'common' | 'video-watch' diff --git a/shared/models/plugins/server-hook.model.ts b/shared/models/plugins/server-hook.model.ts index a7f88f3c4..6729e2dab 100644 --- a/shared/models/plugins/server-hook.model.ts +++ b/shared/models/plugins/server-hook.model.ts @@ -30,5 +30,5 @@ export type ServerActionHookName = export type ServerHookName = ServerFilterHookName | ServerActionHookName export interface ServerHook { - runHook (hookName: ServerHookName, params?: any) + runHook (hookName: ServerHookName, result?: T, params?: any): Promise } diff --git a/shared/models/server/server-config.model.ts b/shared/models/server/server-config.model.ts index 3498f86d7..49bb01708 100644 --- a/shared/models/server/server-config.model.ts +++ b/shared/models/server/server-config.model.ts @@ -1,11 +1,12 @@ import { NSFWPolicyType } from '../videos/nsfw-policy.type' import { ClientScript } from '../plugins/plugin-package-json.model' +import { PluginClientScope } from '../plugins/plugin-scope.type' export interface ServerConfigPlugin { name: string version: string description: string - clientScripts: { [name: string]: ClientScript } + clientScripts: { [name in PluginClientScope]: ClientScript } } export interface ServerConfigTheme extends ServerConfigPlugin { -- cgit v1.2.3