diff options
author | Chocobozzz <me@florianbigard.com> | 2019-07-22 16:31:47 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2019-07-24 10:58:16 +0200 |
commit | 7663e55a2cc46a413bceee2787d48902b15ae642 (patch) | |
tree | c54d620617040642d962f9b8c74c7b8e2d745692 | |
parent | e8f902c05cb35f6d5e9b75a23ddabd51c220a976 (diff) | |
download | PeerTube-7663e55a2cc46a413bceee2787d48902b15ae642.tar.gz PeerTube-7663e55a2cc46a413bceee2787d48902b15ae642.tar.zst PeerTube-7663e55a2cc46a413bceee2787d48902b15ae642.zip |
Log error on unknown hook
9 files changed, 85 insertions, 56 deletions
diff --git a/client/src/app/core/plugins/plugin.service.ts b/client/src/app/core/plugins/plugin.service.ts index 7c1d69bec..90ebe5669 100644 --- a/client/src/app/core/plugins/plugin.service.ts +++ b/client/src/app/core/plugins/plugin.service.ts | |||
@@ -8,7 +8,7 @@ import { RegisterHookOptions } from '@shared/models/plugins/register-hook.model' | |||
8 | import { ReplaySubject } from 'rxjs' | 8 | import { ReplaySubject } from 'rxjs' |
9 | import { first, shareReplay } from 'rxjs/operators' | 9 | import { first, shareReplay } from 'rxjs/operators' |
10 | import { getHookType, internalRunHook } from '@shared/core-utils/plugins/hooks' | 10 | import { getHookType, internalRunHook } from '@shared/core-utils/plugins/hooks' |
11 | import { ClientHook, ClientHookName } from '@shared/models/plugins/client-hook.model' | 11 | import { ClientHook, ClientHookName, clientHookObject } from '@shared/models/plugins/client-hook.model' |
12 | import { PluginClientScope } from '@shared/models/plugins/plugin-client-scope.type' | 12 | import { PluginClientScope } from '@shared/models/plugins/plugin-client-scope.type' |
13 | 13 | ||
14 | interface HookStructValue extends RegisterHookOptions { | 14 | interface HookStructValue extends RegisterHookOptions { |
@@ -155,6 +155,11 @@ export class PluginService implements ClientHook { | |||
155 | const { plugin, clientScript } = pluginInfo | 155 | const { plugin, clientScript } = pluginInfo |
156 | 156 | ||
157 | const registerHook = (options: RegisterHookOptions) => { | 157 | const registerHook = (options: RegisterHookOptions) => { |
158 | if (clientHookObject[options.target] !== true) { | ||
159 | console.error('Unknown hook %s of plugin %s. Skipping.', options.target, plugin.name) | ||
160 | return | ||
161 | } | ||
162 | |||
158 | if (!this.hooks[options.target]) this.hooks[options.target] = [] | 163 | if (!this.hooks[options.target]) this.hooks[options.target] = [] |
159 | 164 | ||
160 | this.hooks[options.target].push({ | 165 | this.hooks[options.target].push({ |
diff --git a/client/src/app/search/search.component.ts b/client/src/app/search/search.component.ts index 55637771e..691e57619 100644 --- a/client/src/app/search/search.component.ts +++ b/client/src/app/search/search.component.ts | |||
@@ -79,6 +79,8 @@ export class SearchComponent implements OnInit, OnDestroy { | |||
79 | 79 | ||
80 | err => this.notifier.error(err.text) | 80 | err => this.notifier.error(err.text) |
81 | ) | 81 | ) |
82 | |||
83 | this.hooks.runAction('action:search.init') | ||
82 | } | 84 | } |
83 | 85 | ||
84 | ngOnDestroy () { | 86 | ngOnDestroy () { |
diff --git a/client/src/app/videos/video-list/video-local.component.ts b/client/src/app/videos/video-list/video-local.component.ts index 81b6ce493..b96e46e6a 100644 --- a/client/src/app/videos/video-list/video-local.component.ts +++ b/client/src/app/videos/video-list/video-local.component.ts | |||
@@ -69,8 +69,8 @@ export class VideoLocalComponent extends AbstractVideoList implements OnInit, On | |||
69 | this.videoService.getVideos.bind(this.videoService), | 69 | this.videoService.getVideos.bind(this.videoService), |
70 | params, | 70 | params, |
71 | 'common', | 71 | 'common', |
72 | 'filter:api.videos.list.local.params', | 72 | 'filter:api.local-videos.videos.list.params', |
73 | 'filter:api.videos.list.local.result' | 73 | 'filter:api.local-videos.videos.list.result' |
74 | ) | 74 | ) |
75 | } | 75 | } |
76 | 76 | ||
diff --git a/client/src/app/videos/video-list/video-recently-added.component.ts b/client/src/app/videos/video-list/video-recently-added.component.ts index 638e7caed..5c50fd396 100644 --- a/client/src/app/videos/video-list/video-recently-added.component.ts +++ b/client/src/app/videos/video-list/video-recently-added.component.ts | |||
@@ -61,8 +61,8 @@ export class VideoRecentlyAddedComponent extends AbstractVideoList implements On | |||
61 | this.videoService.getVideos.bind(this.videoService), | 61 | this.videoService.getVideos.bind(this.videoService), |
62 | params, | 62 | params, |
63 | 'common', | 63 | 'common', |
64 | 'filter:api.videos.list.recently-added.params', | 64 | 'filter:api.recently-added-videos.videos.list.params', |
65 | 'filter:api.videos.list.recently-added.result' | 65 | 'filter:api.recently-added-videos.videos.list.result' |
66 | ) | 66 | ) |
67 | } | 67 | } |
68 | 68 | ||
diff --git a/client/src/app/videos/video-list/video-trending.component.ts b/client/src/app/videos/video-list/video-trending.component.ts index 0e69bfd64..19324da63 100644 --- a/client/src/app/videos/video-list/video-trending.component.ts +++ b/client/src/app/videos/video-list/video-trending.component.ts | |||
@@ -74,8 +74,8 @@ export class VideoTrendingComponent extends AbstractVideoList implements OnInit, | |||
74 | this.videoService.getVideos.bind(this.videoService), | 74 | this.videoService.getVideos.bind(this.videoService), |
75 | params, | 75 | params, |
76 | 'common', | 76 | 'common', |
77 | 'filter:api.videos.list.trending.params', | 77 | 'filter:api.trending-videos.videos.list.params', |
78 | 'filter:api.videos.list.trending.result' | 78 | 'filter:api.trending-videos.videos.list.result' |
79 | ) | 79 | ) |
80 | } | 80 | } |
81 | 81 | ||
diff --git a/client/src/app/videos/video-list/video-user-subscriptions.component.ts b/client/src/app/videos/video-list/video-user-subscriptions.component.ts index ac325aeff..b36c85766 100644 --- a/client/src/app/videos/video-list/video-user-subscriptions.component.ts +++ b/client/src/app/videos/video-list/video-user-subscriptions.component.ts | |||
@@ -57,8 +57,8 @@ export class VideoUserSubscriptionsComponent extends AbstractVideoList implement | |||
57 | this.videoService.getUserSubscriptionVideos.bind(this.videoService), | 57 | this.videoService.getUserSubscriptionVideos.bind(this.videoService), |
58 | params, | 58 | params, |
59 | 'common', | 59 | 'common', |
60 | 'filter:api.videos.list.user-subscriptions.params', | 60 | 'filter:api.user-subscriptions-videos.videos.list.params', |
61 | 'filter:api.videos.list.user-subscriptions.result' | 61 | 'filter:api.user-subscriptions-videos.videos.list.result' |
62 | ) | 62 | ) |
63 | } | 63 | } |
64 | 64 | ||
diff --git a/server/lib/plugins/plugin-manager.ts b/server/lib/plugins/plugin-manager.ts index afc07a151..cfe63e50d 100644 --- a/server/lib/plugins/plugin-manager.ts +++ b/server/lib/plugins/plugin-manager.ts | |||
@@ -13,7 +13,7 @@ import { RegisterSettingOptions } from '../../../shared/models/plugins/register- | |||
13 | import { RegisterHookOptions } from '../../../shared/models/plugins/register-hook.model' | 13 | import { RegisterHookOptions } from '../../../shared/models/plugins/register-hook.model' |
14 | import { PluginSettingsManager } from '../../../shared/models/plugins/plugin-settings-manager.model' | 14 | import { PluginSettingsManager } from '../../../shared/models/plugins/plugin-settings-manager.model' |
15 | import { PluginStorageManager } from '../../../shared/models/plugins/plugin-storage-manager.model' | 15 | import { PluginStorageManager } from '../../../shared/models/plugins/plugin-storage-manager.model' |
16 | import { ServerHook, ServerHookName } from '../../../shared/models/plugins/server-hook.model' | 16 | import { ServerHook, ServerHookName, serverHookObject } from '../../../shared/models/plugins/server-hook.model' |
17 | import { getHookType, internalRunHook } from '../../../shared/core-utils/plugins/hooks' | 17 | import { getHookType, internalRunHook } from '../../../shared/core-utils/plugins/hooks' |
18 | import { RegisterOptions } from '../../typings/plugins/register-options.model' | 18 | import { RegisterOptions } from '../../typings/plugins/register-options.model' |
19 | import { PluginLibrary } from '../../typings/plugins' | 19 | import { PluginLibrary } from '../../typings/plugins' |
@@ -388,6 +388,11 @@ export class PluginManager implements ServerHook { | |||
388 | 388 | ||
389 | private getRegisterHelpers (npmName: string, plugin: PluginModel): RegisterOptions { | 389 | private getRegisterHelpers (npmName: string, plugin: PluginModel): RegisterOptions { |
390 | const registerHook = (options: RegisterHookOptions) => { | 390 | const registerHook = (options: RegisterHookOptions) => { |
391 | if (serverHookObject[options.target] !== true) { | ||
392 | logger.warn('Unknown hook %s of plugin %s. Skipping.', options.target, npmName) | ||
393 | return | ||
394 | } | ||
395 | |||
391 | if (!this.hooks[options.target]) this.hooks[options.target] = [] | 396 | if (!this.hooks[options.target]) this.hooks[options.target] = [] |
392 | 397 | ||
393 | this.hooks[options.target].push({ | 398 | this.hooks[options.target].push({ |
diff --git a/shared/models/plugins/client-hook.model.ts b/shared/models/plugins/client-hook.model.ts index 89400003e..bf444fe5a 100644 --- a/shared/models/plugins/client-hook.model.ts +++ b/shared/models/plugins/client-hook.model.ts | |||
@@ -1,38 +1,48 @@ | |||
1 | export type ClientFilterHookName = | 1 | // Data from API hooks: {hookType}:api.{location}.{elementType}.{actionType}.{target} |
2 | 'filter:api.videos.list.trending.params' | | ||
3 | 'filter:api.videos.list.trending.result' | | ||
4 | 2 | ||
5 | 'filter:api.videos.list.local.params' | | 3 | export const clientFilterHookObject = { |
6 | 'filter:api.videos.list.local.result' | | 4 | 'filter:api.trending-videos.videos.list.params': true, |
5 | 'filter:api.trending-videos.videos.list.result': true, | ||
7 | 6 | ||
8 | 'filter:api.videos.list.recently-added.params' | | 7 | 'filter:api.local-videos.videos.list.params': true, |
9 | 'filter:api.videos.list.recently-added.result' | | 8 | 'filter:api.local-videos.videos.list.result': true, |
10 | 9 | ||
11 | 'filter:api.videos.list.user-subscriptions.params' | | 10 | 'filter:api.recently-added-videos.videos.list.params': true, |
12 | 'filter:api.videos.list.user-subscriptions.result' | | 11 | 'filter:api.recently-added-videos.videos.list.result': true, |
13 | 12 | ||
14 | 'filter:api.video-watch.video.get.params' | | 13 | 'filter:api.user-subscriptions-videos.videos.list.params': true, |
15 | 'filter:api.video-watch.video.get.result' | | 14 | 'filter:api.user-subscriptions-videos.videos.list.result': true, |
16 | 15 | ||
17 | 'filter:api.video-watch.video-threads.list.params' | | 16 | 'filter:api.video-watch.video.get.params': true, |
18 | 'filter:api.video-watch.video-threads.list.result' | | 17 | 'filter:api.video-watch.video.get.result': true, |
19 | 18 | ||
20 | 'filter:api.video-watch.video-thread-replies.list.params' | | 19 | 'filter:api.video-watch.video-threads.list.params': true, |
21 | 'filter:api.video-watch.video-thread-replies.list.result' | | 20 | 'filter:api.video-watch.video-threads.list.result': true, |
22 | 21 | ||
23 | 'filter:api.search.videos.list.params' | | 22 | 'filter:api.video-watch.video-thread-replies.list.params': true, |
24 | 'filter:api.search.videos.list.result' | | 23 | 'filter:api.video-watch.video-thread-replies.list.result': true, |
25 | 'filter:api.search.video-channels.list.params' | | ||
26 | 'filter:api.search.video-channels.list.result' | ||
27 | 24 | ||
28 | export type ClientActionHookName = | 25 | 'filter:api.search.videos.list.params': true, |
29 | 'action:application.init' | | 26 | 'filter:api.search.videos.list.result': true, |
27 | 'filter:api.search.video-channels.list.params': true, | ||
28 | 'filter:api.search.video-channels.list.result': true | ||
29 | } | ||
30 | |||
31 | export type ClientFilterHookName = keyof typeof clientFilterHookObject | ||
32 | |||
33 | export const clientActionHookObject = { | ||
34 | 'action:application.init': true, | ||
30 | 35 | ||
31 | 'action:video-watch.init' | | 36 | 'action:video-watch.init': true, |
37 | 'action:video-watch.video.loaded': true, | ||
38 | |||
39 | 'action:search.init': true | ||
40 | } | ||
32 | 41 | ||
33 | 'action:video-watch.video.loaded' | 42 | export type ClientActionHookName = keyof typeof clientActionHookObject |
34 | 43 | ||
35 | export type ClientHookName = ClientActionHookName | ClientFilterHookName | 44 | export const clientHookObject = Object.assign({}, clientFilterHookObject, clientActionHookObject) |
45 | export type ClientHookName = keyof typeof clientHookObject | ||
36 | 46 | ||
37 | export interface ClientHook { | 47 | export interface ClientHook { |
38 | runHook <T> (hookName: ClientHookName, result?: T, params?: any): Promise<T> | 48 | runHook <T> (hookName: ClientHookName, result?: T, params?: any): Promise<T> |
diff --git a/shared/models/plugins/server-hook.model.ts b/shared/models/plugins/server-hook.model.ts index 6729e2dab..f53e0ce59 100644 --- a/shared/models/plugins/server-hook.model.ts +++ b/shared/models/plugins/server-hook.model.ts | |||
@@ -1,33 +1,40 @@ | |||
1 | export type ServerFilterHookName = | 1 | export const serverFilterHookObject = { |
2 | 'filter:api.videos.list.params' | | 2 | 'filter:api.videos.list.params': true, |
3 | 'filter:api.videos.list.result' | | 3 | 'filter:api.videos.list.result': true, |
4 | 'filter:api.video.get.result' | | 4 | 'filter:api.video.get.result': true, |
5 | 5 | ||
6 | 'filter:api.video.upload.accept.result' | | 6 | 'filter:api.video.upload.accept.result': true, |
7 | 'filter:api.video-thread.create.accept.result' | | 7 | 'filter:api.video-thread.create.accept.result': true, |
8 | 'filter:api.video-comment-reply.create.accept.result' | | 8 | 'filter:api.video-comment-reply.create.accept.result': true, |
9 | 9 | ||
10 | 'filter:api.video-threads.list.params' | | 10 | 'filter:api.video-threads.list.params': true, |
11 | 'filter:api.video-threads.list.result' | | 11 | 'filter:api.video-threads.list.result': true, |
12 | 12 | ||
13 | 'filter:api.video-thread-comments.list.params' | | 13 | 'filter:api.video-thread-comments.list.params': true, |
14 | 'filter:api.video-thread-comments.list.result' | | 14 | 'filter:api.video-thread-comments.list.result': true, |
15 | 15 | ||
16 | 'filter:video.auto-blacklist.result' | 16 | 'filter:video.auto-blacklist.result': true |
17 | } | ||
18 | |||
19 | export type ServerFilterHookName = keyof typeof serverFilterHookObject | ||
17 | 20 | ||
18 | export type ServerActionHookName = | 21 | export const serverActionHookObject = { |
19 | 'action:application.listening' | | 22 | 'action:application.listening': true, |
20 | 23 | ||
21 | 'action:api.video.updated' | | 24 | 'action:api.video.updated': true, |
22 | 'action:api.video.deleted' | | 25 | 'action:api.video.deleted': true, |
23 | 'action:api.video.uploaded' | | 26 | 'action:api.video.uploaded': true, |
24 | 'action:api.video.viewed' | | 27 | 'action:api.video.viewed': true, |
28 | |||
29 | 'action:api.video-thread.created': true, | ||
30 | 'action:api.video-comment-reply.created': true, | ||
31 | 'action:api.video-comment.deleted': true | ||
32 | } | ||
25 | 33 | ||
26 | 'action:api.video-thread.created' | | 34 | export type ServerActionHookName = keyof typeof serverActionHookObject |
27 | 'action:api.video-comment-reply.created' | | ||
28 | 'action:api.video-comment.deleted' | ||
29 | 35 | ||
30 | export type ServerHookName = ServerFilterHookName | ServerActionHookName | 36 | export const serverHookObject = Object.assign({}, serverFilterHookObject, serverActionHookObject) |
37 | export type ServerHookName = keyof typeof serverHookObject | ||
31 | 38 | ||
32 | export interface ServerHook { | 39 | export interface ServerHook { |
33 | runHook <T> (hookName: ServerHookName, result?: T, params?: any): Promise<T> | 40 | runHook <T> (hookName: ServerHookName, result?: T, params?: any): Promise<T> |