Log error on unknown hook

This commit is contained in:
Chocobozzz 2019-07-22 16:31:47 +02:00 committed by Chocobozzz
parent e8f902c05c
commit 7663e55a2c
9 changed files with 85 additions and 56 deletions

View 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({

View File

@ -79,6 +79,8 @@ export class SearchComponent implements OnInit, OnDestroy {
err => this.notifier.error(err.text)
)
this.hooks.runAction('action:search.init')
}
ngOnDestroy () {

View 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'
)
}

View 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'
)
}

View 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'
)
}

View 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'
)
}

View 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({

View 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
}
'action:video-watch.init' |
export type ClientFilterHookName = keyof typeof clientFilterHookObject
'action:video-watch.video.loaded'
export const clientActionHookObject = {
'action:application.init': true,
export type ClientHookName = ClientActionHookName | ClientFilterHookName
'action:video-watch.init': true,
'action:video-watch.video.loaded': true,
'action:search.init': true
}
export type ClientActionHookName = keyof typeof clientActionHookObject
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>

View 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 ServerActionHookName =
'action:application.listening' |
export type ServerFilterHookName = keyof typeof serverFilterHookObject
'action:api.video.updated' |
'action:api.video.deleted' |
'action:api.video.uploaded' |
'action:api.video.viewed' |
export const serverActionHookObject = {
'action:application.listening': true,
'action:api.video-thread.created' |
'action:api.video-comment-reply.created' |
'action:api.video-comment.deleted'
'action:api.video.updated': true,
'action:api.video.deleted': true,
'action:api.video.uploaded': true,
'action:api.video.viewed': true,
export type ServerHookName = ServerFilterHookName | ServerActionHookName
'action:api.video-thread.created': true,
'action:api.video-comment-reply.created': true,
'action:api.video-comment.deleted': true
}
export type ServerActionHookName = keyof typeof serverActionHookObject
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>