From: Chocobozzz Date: Mon, 22 Jul 2019 14:31:47 +0000 (+0200) Subject: Log error on unknown hook X-Git-Tag: v1.4.0-rc.1~91 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=7663e55a2cc46a413bceee2787d48902b15ae642;p=oweals%2Fpeertube.git Log error on unknown hook --- 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' 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({ 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 { err => this.notifier.error(err.text) ) + + this.hooks.runAction('action:search.init') } 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 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' ) } 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 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' ) } 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, 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' ) } 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 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' ) } 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- 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({ 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 @@ -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 (hookName: ClientHookName, result?: T, params?: any): Promise 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 @@ -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 (hookName: ServerHookName, result?: T, params?: any): Promise