Log error on unknown hook
authorChocobozzz <me@florianbigard.com>
Mon, 22 Jul 2019 14:31:47 +0000 (16:31 +0200)
committerChocobozzz <chocobozzz@cpy.re>
Wed, 24 Jul 2019 08:58:16 +0000 (10:58 +0200)
client/src/app/core/plugins/plugin.service.ts
client/src/app/search/search.component.ts
client/src/app/videos/video-list/video-local.component.ts
client/src/app/videos/video-list/video-recently-added.component.ts
client/src/app/videos/video-list/video-trending.component.ts
client/src/app/videos/video-list/video-user-subscriptions.component.ts
server/lib/plugins/plugin-manager.ts
shared/models/plugins/client-hook.model.ts
shared/models/plugins/server-hook.model.ts

index 7c1d69bec49a0c822a66029a6b8a580092a5b492..90ebe56690923b618743f7c8dbe85212119ee924 100644 (file)
@@ -8,7 +8,7 @@ import { RegisterHookOptions } from '@shared/models/plugins/register-hook.model'
 import { ReplaySubject } from 'rxjs'
 import { first, shareReplay } from 'rxjs/operators'
 import { getHookType, internalRunHook } from '@shared/core-utils/plugins/hooks'
-import { ClientHook, ClientHookName } from '@shared/models/plugins/client-hook.model'
+import { ClientHook, ClientHookName, clientHookObject } from '@shared/models/plugins/client-hook.model'
 import { PluginClientScope } from '@shared/models/plugins/plugin-client-scope.type'
 
 interface HookStructValue extends RegisterHookOptions {
@@ -155,6 +155,11 @@ export class PluginService implements ClientHook {
     const { plugin, clientScript } = pluginInfo
 
     const registerHook = (options: RegisterHookOptions) => {
+      if (clientHookObject[options.target] !== true) {
+        console.error('Unknown hook %s of plugin %s. Skipping.', options.target, plugin.name)
+        return
+      }
+
       if (!this.hooks[options.target]) this.hooks[options.target] = []
 
       this.hooks[options.target].push({
index 55637771e45f76fb042103e2f93feefbfe8fd0f1..691e57619543eea0ea62592cf44d189b904eb9e9 100644 (file)
@@ -79,6 +79,8 @@ export class SearchComponent implements OnInit, OnDestroy {
 
       err => this.notifier.error(err.text)
     )
+
+    this.hooks.runAction('action:search.init')
   }
 
   ngOnDestroy () {
index 81b6ce49334444a3a584847727ff791e2d8ada86..b96e46e6a9ca899916c7530b12109c118ac7cd3f 100644 (file)
@@ -69,8 +69,8 @@ export class VideoLocalComponent extends AbstractVideoList implements OnInit, On
       this.videoService.getVideos.bind(this.videoService),
       params,
       'common',
-      'filter:api.videos.list.local.params',
-      'filter:api.videos.list.local.result'
+      'filter:api.local-videos.videos.list.params',
+      'filter:api.local-videos.videos.list.result'
     )
   }
 
index 638e7caed24611764801061fa5d7a1061e21d552..5c50fd396eee4b867ff616b3071788aa2bbc5d5a 100644 (file)
@@ -61,8 +61,8 @@ export class VideoRecentlyAddedComponent extends AbstractVideoList implements On
       this.videoService.getVideos.bind(this.videoService),
       params,
       'common',
-      'filter:api.videos.list.recently-added.params',
-      'filter:api.videos.list.recently-added.result'
+      'filter:api.recently-added-videos.videos.list.params',
+      'filter:api.recently-added-videos.videos.list.result'
     )
   }
 
index 0e69bfd645e23cc0fd981717f246f305ea8f1679..19324da633ac0f30fa568e53824b4cd264a3b517 100644 (file)
@@ -74,8 +74,8 @@ export class VideoTrendingComponent extends AbstractVideoList implements OnInit,
       this.videoService.getVideos.bind(this.videoService),
       params,
       'common',
-      'filter:api.videos.list.trending.params',
-      'filter:api.videos.list.trending.result'
+      'filter:api.trending-videos.videos.list.params',
+      'filter:api.trending-videos.videos.list.result'
     )
   }
 
index ac325aeff1f25829e158990141e77f45deb846c6..b36c857666f9217cc3c31f42f2a24c255bad5ae7 100644 (file)
@@ -57,8 +57,8 @@ export class VideoUserSubscriptionsComponent extends AbstractVideoList implement
       this.videoService.getUserSubscriptionVideos.bind(this.videoService),
       params,
       'common',
-      'filter:api.videos.list.user-subscriptions.params',
-      'filter:api.videos.list.user-subscriptions.result'
+      'filter:api.user-subscriptions-videos.videos.list.params',
+      'filter:api.user-subscriptions-videos.videos.list.result'
     )
   }
 
index afc07a1511ccab86d87144575ba78e7fcb6d2a8d..cfe63e50d1a681dc1d94028382572a88a0b15cdd 100644 (file)
@@ -13,7 +13,7 @@ import { RegisterSettingOptions } from '../../../shared/models/plugins/register-
 import { RegisterHookOptions } from '../../../shared/models/plugins/register-hook.model'
 import { PluginSettingsManager } from '../../../shared/models/plugins/plugin-settings-manager.model'
 import { PluginStorageManager } from '../../../shared/models/plugins/plugin-storage-manager.model'
-import { ServerHook, ServerHookName } from '../../../shared/models/plugins/server-hook.model'
+import { ServerHook, ServerHookName, serverHookObject } from '../../../shared/models/plugins/server-hook.model'
 import { getHookType, internalRunHook } from '../../../shared/core-utils/plugins/hooks'
 import { RegisterOptions } from '../../typings/plugins/register-options.model'
 import { PluginLibrary } from '../../typings/plugins'
@@ -388,6 +388,11 @@ export class PluginManager implements ServerHook {
 
   private getRegisterHelpers (npmName: string, plugin: PluginModel): RegisterOptions {
     const registerHook = (options: RegisterHookOptions) => {
+      if (serverHookObject[options.target] !== true) {
+        logger.warn('Unknown hook %s of plugin %s. Skipping.', options.target, npmName)
+        return
+      }
+
       if (!this.hooks[options.target]) this.hooks[options.target] = []
 
       this.hooks[options.target].push({
index 89400003e4f5f8e98968ae1e73744532144b7852..bf444fe5afa4879bec86d734ab96965c9f9fa360 100644 (file)
@@ -1,38 +1,48 @@
-export type ClientFilterHookName =
-  'filter:api.videos.list.trending.params' |
-  'filter:api.videos.list.trending.result' |
+// Data from API hooks: {hookType}:api.{location}.{elementType}.{actionType}.{target}
 
-  'filter:api.videos.list.local.params' |
-  'filter:api.videos.list.local.result' |
+export const clientFilterHookObject = {
+  'filter:api.trending-videos.videos.list.params': true,
+  'filter:api.trending-videos.videos.list.result': true,
 
-  'filter:api.videos.list.recently-added.params' |
-  'filter:api.videos.list.recently-added.result' |
+  'filter:api.local-videos.videos.list.params': true,
+  'filter:api.local-videos.videos.list.result': true,
 
-  'filter:api.videos.list.user-subscriptions.params' |
-  'filter:api.videos.list.user-subscriptions.result' |
+  'filter:api.recently-added-videos.videos.list.params': true,
+  'filter:api.recently-added-videos.videos.list.result': true,
 
-  'filter:api.video-watch.video.get.params' |
-  'filter:api.video-watch.video.get.result' |
+  'filter:api.user-subscriptions-videos.videos.list.params': true,
+  'filter:api.user-subscriptions-videos.videos.list.result': true,
 
-  'filter:api.video-watch.video-threads.list.params' |
-  'filter:api.video-watch.video-threads.list.result' |
+  'filter:api.video-watch.video.get.params': true,
+  'filter:api.video-watch.video.get.result': true,
 
-  'filter:api.video-watch.video-thread-replies.list.params' |
-  'filter:api.video-watch.video-thread-replies.list.result' |
+  'filter:api.video-watch.video-threads.list.params': true,
+  'filter:api.video-watch.video-threads.list.result': true,
 
-  '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'
+  'filter:api.video-watch.video-thread-replies.list.params': true,
+  'filter:api.video-watch.video-thread-replies.list.result': true,
 
-export type ClientActionHookName =
-  'action:application.init' |
+  'filter:api.search.videos.list.params': true,
+  'filter:api.search.videos.list.result': true,
+  'filter:api.search.video-channels.list.params': true,
+  'filter:api.search.video-channels.list.result': true
+}
+
+export type ClientFilterHookName = keyof typeof clientFilterHookObject
+
+export const clientActionHookObject = {
+  'action:application.init': true,
 
-  'action:video-watch.init' |
+  'action:video-watch.init': true,
+  'action:video-watch.video.loaded': true,
+
+  'action:search.init': true
+}
 
-  'action:video-watch.video.loaded'
+export type ClientActionHookName = keyof typeof clientActionHookObject
 
-export type ClientHookName = ClientActionHookName | ClientFilterHookName
+export const clientHookObject = Object.assign({}, clientFilterHookObject, clientActionHookObject)
+export type ClientHookName = keyof typeof clientHookObject
 
 export interface ClientHook {
   runHook <T> (hookName: ClientHookName, result?: T, params?: any): Promise<T>
index 6729e2dabab4f581be6bb4b90366835e8ef634a9..f53e0ce597d5cbd9010943d6054b2319b910cade 100644 (file)
@@ -1,33 +1,40 @@
-export type ServerFilterHookName =
-  'filter:api.videos.list.params' |
-  'filter:api.videos.list.result' |
-  'filter:api.video.get.result' |
+export const serverFilterHookObject = {
+  'filter:api.videos.list.params': true,
+  'filter:api.videos.list.result': true,
+  'filter:api.video.get.result': true,
 
-  'filter:api.video.upload.accept.result' |
-  'filter:api.video-thread.create.accept.result' |
-  'filter:api.video-comment-reply.create.accept.result' |
+  'filter:api.video.upload.accept.result': true,
+  'filter:api.video-thread.create.accept.result': true,
+  'filter:api.video-comment-reply.create.accept.result': true,
 
-  'filter:api.video-threads.list.params' |
-  'filter:api.video-threads.list.result' |
+  'filter:api.video-threads.list.params': true,
+  'filter:api.video-threads.list.result': true,
 
-  'filter:api.video-thread-comments.list.params' |
-  'filter:api.video-thread-comments.list.result' |
+  'filter:api.video-thread-comments.list.params': true,
+  'filter:api.video-thread-comments.list.result': true,
 
-  'filter:video.auto-blacklist.result'
+  'filter:video.auto-blacklist.result': true
+}
+
+export type ServerFilterHookName = keyof typeof serverFilterHookObject
 
-export type ServerActionHookName =
-  'action:application.listening' |
+export const serverActionHookObject = {
+  'action:application.listening': true,
 
-  'action:api.video.updated' |
-  'action:api.video.deleted' |
-  'action:api.video.uploaded' |
-  'action:api.video.viewed' |
+  'action:api.video.updated': true,
+  'action:api.video.deleted': true,
+  'action:api.video.uploaded': true,
+  'action:api.video.viewed': true,
+
+  'action:api.video-thread.created': true,
+  'action:api.video-comment-reply.created': true,
+  'action:api.video-comment.deleted': true
+}
 
-  'action:api.video-thread.created' |
-  'action:api.video-comment-reply.created' |
-  'action:api.video-comment.deleted'
+export type ServerActionHookName = keyof typeof serverActionHookObject
 
-export type ServerHookName = ServerFilterHookName | ServerActionHookName
+export const serverHookObject = Object.assign({}, serverFilterHookObject, serverActionHookObject)
+export type ServerHookName = keyof typeof serverHookObject
 
 export interface ServerHook {
   runHook <T> (hookName: ServerHookName, result?: T, params?: any): Promise<T>