From 9ae88819c202a6ce4a36b56506f508a5603e8eab Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 24 Jul 2019 11:17:42 +0200 Subject: [PATCH] Change plugin models names --- .../plugin-show-installed.component.ts | 4 ++-- .../+admin/plugins/shared/plugin-api.service.ts | 4 ++-- client/src/app/core/plugins/plugin.service.ts | 6 +++--- server/controllers/api/plugins.ts | 4 ++-- server/lib/plugins/plugin-manager.ts | 14 +++++++------- server/tests/api/server/plugins.ts | 4 ++-- server/typings/plugins/index.d.ts | 2 +- server/typings/plugins/plugin-library.model.ts | 4 ++-- ...ns.model.ts => register-server-option.model.ts} | 10 +++++----- .../models/plugins/register-client-hook.model.ts | 7 +++++++ shared/models/plugins/register-hook.model.ts | 5 ----- .../models/plugins/register-server-hook.model.ts | 7 +++++++ .../plugins/register-server-setting.model.ts | 10 ++++++++++ shared/models/plugins/register-setting.model.ts | 10 ---------- 14 files changed, 50 insertions(+), 41 deletions(-) rename server/typings/plugins/{register-options.model.ts => register-server-option.model.ts} (50%) create mode 100644 shared/models/plugins/register-client-hook.model.ts delete mode 100644 shared/models/plugins/register-hook.model.ts create mode 100644 shared/models/plugins/register-server-hook.model.ts create mode 100644 shared/models/plugins/register-server-setting.model.ts delete mode 100644 shared/models/plugins/register-setting.model.ts diff --git a/client/src/app/+admin/plugins/plugin-show-installed/plugin-show-installed.component.ts b/client/src/app/+admin/plugins/plugin-show-installed/plugin-show-installed.component.ts index 0fbd65160..569d98482 100644 --- a/client/src/app/+admin/plugins/plugin-show-installed/plugin-show-installed.component.ts +++ b/client/src/app/+admin/plugins/plugin-show-installed/plugin-show-installed.component.ts @@ -6,8 +6,8 @@ import { Notifier } from '@app/core' import { ActivatedRoute } from '@angular/router' import { Subscription } from 'rxjs' import { map, switchMap } from 'rxjs/operators' -import { RegisterSettingOptions } from '@shared/models/plugins/register-setting.model' import { BuildFormArgument, FormReactive, FormValidatorService } from '@app/shared' +import { RegisterServerSettingOptions } from '@shared/models/plugins/register-server-setting.model' @Component({ selector: 'my-plugin-show-installed', @@ -16,7 +16,7 @@ import { BuildFormArgument, FormReactive, FormValidatorService } from '@app/shar }) export class PluginShowInstalledComponent extends FormReactive implements OnInit, OnDestroy { plugin: PeerTubePlugin - registeredSettings: RegisterSettingOptions[] = [] + registeredSettings: RegisterServerSettingOptions[] = [] pluginTypeLabel: string private sub: Subscription diff --git a/client/src/app/+admin/plugins/shared/plugin-api.service.ts b/client/src/app/+admin/plugins/shared/plugin-api.service.ts index 51f086a93..bfcaec011 100644 --- a/client/src/app/+admin/plugins/shared/plugin-api.service.ts +++ b/client/src/app/+admin/plugins/shared/plugin-api.service.ts @@ -10,8 +10,8 @@ import { ResultList } from '@shared/models' import { PeerTubePlugin } from '@shared/models/plugins/peertube-plugin.model' import { ManagePlugin } from '@shared/models/plugins/manage-plugin.model' import { InstallOrUpdatePlugin } from '@shared/models/plugins/install-plugin.model' -import { RegisterSettingOptions } from '@shared/models/plugins/register-setting.model' import { PeerTubePluginIndex } from '@shared/models/plugins/peertube-plugin-index.model' +import { RegisterServerSettingOptions } from '@shared/models/plugins/register-server-setting.model' @Injectable() export class PluginApiService { @@ -88,7 +88,7 @@ export class PluginApiService { getPluginRegisteredSettings (pluginName: string, pluginType: PluginType) { const path = PluginApiService.BASE_APPLICATION_URL + '/' + this.nameToNpmName(pluginName, pluginType) + '/registered-settings' - return this.authHttp.get<{ settings: RegisterSettingOptions[] }>(path) + return this.authHttp.get<{ settings: RegisterServerSettingOptions[] }>(path) .pipe(catchError(res => this.restExtractor.handleError(res))) } diff --git a/client/src/app/core/plugins/plugin.service.ts b/client/src/app/core/plugins/plugin.service.ts index 5d180e5a0..e4a73de81 100644 --- a/client/src/app/core/plugins/plugin.service.ts +++ b/client/src/app/core/plugins/plugin.service.ts @@ -4,14 +4,14 @@ import { ServerConfigPlugin } from '@shared/models' import { ServerService } from '@app/core/server/server.service' import { ClientScript } from '@shared/models/plugins/plugin-package-json.model' import { environment } from '../../../environments/environment' -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, clientHookObject } from '@shared/models/plugins/client-hook.model' import { PluginClientScope } from '@shared/models/plugins/plugin-client-scope.type' +import { RegisterClientHookOptions } from '@shared/models/plugins/register-client-hook.model' -interface HookStructValue extends RegisterHookOptions { +interface HookStructValue extends RegisterClientHookOptions { plugin: ServerConfigPlugin clientScript: ClientScript } @@ -164,7 +164,7 @@ export class PluginService implements ClientHook { private loadPlugin (pluginInfo: PluginInfo) { const { plugin, clientScript } = pluginInfo - const registerHook = (options: RegisterHookOptions) => { + const registerHook = (options: RegisterClientHookOptions) => { if (clientHookObject[options.target] !== true) { console.error('Unknown hook %s of plugin %s. Skipping.', options.target, plugin.name) return diff --git a/server/controllers/api/plugins.ts b/server/controllers/api/plugins.ts index de58a7350..86384ee27 100644 --- a/server/controllers/api/plugins.ts +++ b/server/controllers/api/plugins.ts @@ -25,7 +25,7 @@ import { ManagePlugin } from '../../../shared/models/plugins/manage-plugin.model import { logger } from '../../helpers/logger' import { listAvailablePluginsFromIndex } from '../../lib/plugins/plugin-index' import { PeertubePluginIndexList } from '../../../shared/models/plugins/peertube-plugin-index-list.model' -import { RegisteredSettings } from '../../../shared/models/plugins/register-setting.model' +import { RegisteredServerSettings } from '../../../shared/models/plugins/register-server-setting.model' const pluginRouter = express.Router() @@ -164,7 +164,7 @@ async function uninstallPlugin (req: express.Request, res: express.Response) { function getPluginRegisteredSettings (req: express.Request, res: express.Response) { const settings = PluginManager.Instance.getRegisteredSettings(req.params.npmName) - const json: RegisteredSettings = { settings } + const json: RegisteredServerSettings = { settings } return res.json(json) } diff --git a/server/lib/plugins/plugin-manager.ts b/server/lib/plugins/plugin-manager.ts index a87d02c56..381a89473 100644 --- a/server/lib/plugins/plugin-manager.ts +++ b/server/lib/plugins/plugin-manager.ts @@ -9,15 +9,15 @@ import { PLUGIN_GLOBAL_CSS_PATH } from '../../initializers/constants' import { PluginType } from '../../../shared/models/plugins/plugin.type' import { installNpmPlugin, installNpmPluginFromDisk, removeNpmPlugin } from './yarn' import { outputFile, readJSON } from 'fs-extra' -import { RegisterSettingOptions } from '../../../shared/models/plugins/register-setting.model' -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, 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 { RegisterServerOptions } from '../../typings/plugins/register-server-option.model' import { PluginLibrary } from '../../typings/plugins' import { ClientHtml } from '../client-html' +import { RegisterServerHookOptions } from '../../../shared/models/plugins/register-server-hook.model' +import { RegisterServerSettingOptions } from '../../../shared/models/plugins/register-server-setting.model' export interface RegisteredPlugin { npmName: string @@ -51,7 +51,7 @@ export class PluginManager implements ServerHook { private static instance: PluginManager private registeredPlugins: { [ name: string ]: RegisteredPlugin } = {} - private settings: { [ name: string ]: RegisterSettingOptions[] } = {} + private settings: { [ name: string ]: RegisterServerSettingOptions[] } = {} private hooks: { [ name: string ]: HookInformationValue[] } = {} private constructor () { @@ -391,8 +391,8 @@ export class PluginManager implements ServerHook { // ###################### Generate register helpers ###################### - private getRegisterHelpers (npmName: string, plugin: PluginModel): RegisterOptions { - const registerHook = (options: RegisterHookOptions) => { + private getRegisterHelpers (npmName: string, plugin: PluginModel): RegisterServerOptions { + const registerHook = (options: RegisterServerHookOptions) => { if (serverHookObject[options.target] !== true) { logger.warn('Unknown hook %s of plugin %s. Skipping.', options.target, npmName) return @@ -408,7 +408,7 @@ export class PluginManager implements ServerHook { }) } - const registerSetting = (options: RegisterSettingOptions) => { + const registerSetting = (options: RegisterServerSettingOptions) => { if (!this.settings[npmName]) this.settings[npmName] = [] this.settings[npmName].push(options) diff --git a/server/tests/api/server/plugins.ts b/server/tests/api/server/plugins.ts index b3d003f45..f8b2d78c9 100644 --- a/server/tests/api/server/plugins.ts +++ b/server/tests/api/server/plugins.ts @@ -23,10 +23,10 @@ import { import { PluginType } from '../../../../shared/models/plugins/plugin.type' import { PeerTubePluginIndex } from '../../../../shared/models/plugins/peertube-plugin-index.model' import { ServerConfig } from '../../../../shared/models/server' -import { RegisteredSettings } from '../../../../shared/models/plugins/register-setting.model' import { PeerTubePlugin } from '../../../../shared/models/plugins/peertube-plugin.model' import { User } from '../../../../shared/models/users' import { PluginPackageJson } from '../../../../shared/models/plugins/plugin-package-json.model' +import { RegisteredServerSettings } from '../../../../shared/models/plugins/register-server-setting.model' const expect = chai.expect @@ -217,7 +217,7 @@ describe('Test plugins', function () { npmName: 'peertube-plugin-hello-world' }) - const settings = (res.body as RegisteredSettings).settings + const settings = (res.body as RegisteredServerSettings).settings expect(settings).to.have.length.at.least(1) diff --git a/server/typings/plugins/index.d.ts b/server/typings/plugins/index.d.ts index bddb3089e..9570579ef 100644 --- a/server/typings/plugins/index.d.ts +++ b/server/typings/plugins/index.d.ts @@ -1,2 +1,2 @@ -export * from './register-options.model' +export * from './register-server-option.model' export * from './plugin-library.model' diff --git a/server/typings/plugins/plugin-library.model.ts b/server/typings/plugins/plugin-library.model.ts index fd90a3b46..5b517ee9f 100644 --- a/server/typings/plugins/plugin-library.model.ts +++ b/server/typings/plugins/plugin-library.model.ts @@ -1,7 +1,7 @@ -import { RegisterOptions } from './register-options.model' +import { RegisterServerOptions } from './register-server-option.model' export interface PluginLibrary { - register: (options: RegisterOptions) => Promise + register: (options: RegisterServerOptions) => Promise unregister: () => Promise } diff --git a/server/typings/plugins/register-options.model.ts b/server/typings/plugins/register-server-option.model.ts similarity index 50% rename from server/typings/plugins/register-options.model.ts rename to server/typings/plugins/register-server-option.model.ts index 007ef5e1b..91a06a7c5 100644 --- a/server/typings/plugins/register-options.model.ts +++ b/server/typings/plugins/register-server-option.model.ts @@ -1,13 +1,13 @@ import { logger } from '../../helpers/logger' -import { RegisterHookOptions } from '../../../shared/models/plugins/register-hook.model' -import { RegisterSettingOptions } from '../../../shared/models/plugins/register-setting.model' import { PluginSettingsManager } from '../../../shared/models/plugins/plugin-settings-manager.model' import { PluginStorageManager } from '../../../shared/models/plugins/plugin-storage-manager.model' +import { RegisterServerHookOptions } from '../../../shared/models/plugins/register-server-hook.model' +import { RegisterServerSettingOptions } from '../../../shared/models/plugins/register-server-setting.model' -export type RegisterOptions = { - registerHook: (options: RegisterHookOptions) => void +export type RegisterServerOptions = { + registerHook: (options: RegisterServerHookOptions) => void - registerSetting: (options: RegisterSettingOptions) => void + registerSetting: (options: RegisterServerSettingOptions) => void settingsManager: PluginSettingsManager diff --git a/shared/models/plugins/register-client-hook.model.ts b/shared/models/plugins/register-client-hook.model.ts new file mode 100644 index 000000000..81047b21d --- /dev/null +++ b/shared/models/plugins/register-client-hook.model.ts @@ -0,0 +1,7 @@ +import { ClientHookName } from './client-hook.model' + +export interface RegisterClientHookOptions { + target: ClientHookName + handler: Function + priority?: number +} diff --git a/shared/models/plugins/register-hook.model.ts b/shared/models/plugins/register-hook.model.ts deleted file mode 100644 index 0ed2157bd..000000000 --- a/shared/models/plugins/register-hook.model.ts +++ /dev/null @@ -1,5 +0,0 @@ -export interface RegisterHookOptions { - target: string - handler: Function - priority?: number -} diff --git a/shared/models/plugins/register-server-hook.model.ts b/shared/models/plugins/register-server-hook.model.ts new file mode 100644 index 000000000..746fdc329 --- /dev/null +++ b/shared/models/plugins/register-server-hook.model.ts @@ -0,0 +1,7 @@ +import { ServerHookName } from './server-hook.model' + +export interface RegisterServerHookOptions { + target: ServerHookName + handler: Function + priority?: number +} diff --git a/shared/models/plugins/register-server-setting.model.ts b/shared/models/plugins/register-server-setting.model.ts new file mode 100644 index 000000000..5dea93c39 --- /dev/null +++ b/shared/models/plugins/register-server-setting.model.ts @@ -0,0 +1,10 @@ +export interface RegisterServerSettingOptions { + name: string + label: string + type: 'input' + default?: string +} + +export interface RegisteredServerSettings { + settings: RegisterServerSettingOptions[] +} diff --git a/shared/models/plugins/register-setting.model.ts b/shared/models/plugins/register-setting.model.ts deleted file mode 100644 index 429ac3aad..000000000 --- a/shared/models/plugins/register-setting.model.ts +++ /dev/null @@ -1,10 +0,0 @@ -export interface RegisterSettingOptions { - name: string - label: string - type: 'input' - default?: string -} - -export interface RegisteredSettings { - settings: RegisterSettingOptions[] -} -- 2.25.1