Change plugin models names
authorChocobozzz <me@florianbigard.com>
Wed, 24 Jul 2019 09:17:42 +0000 (11:17 +0200)
committerChocobozzz <me@florianbigard.com>
Wed, 24 Jul 2019 09:17:42 +0000 (11:17 +0200)
15 files changed:
client/src/app/+admin/plugins/plugin-show-installed/plugin-show-installed.component.ts
client/src/app/+admin/plugins/shared/plugin-api.service.ts
client/src/app/core/plugins/plugin.service.ts
server/controllers/api/plugins.ts
server/lib/plugins/plugin-manager.ts
server/tests/api/server/plugins.ts
server/typings/plugins/index.d.ts
server/typings/plugins/plugin-library.model.ts
server/typings/plugins/register-options.model.ts [deleted file]
server/typings/plugins/register-server-option.model.ts [new file with mode: 0644]
shared/models/plugins/register-client-hook.model.ts [new file with mode: 0644]
shared/models/plugins/register-hook.model.ts [deleted file]
shared/models/plugins/register-server-hook.model.ts [new file with mode: 0644]
shared/models/plugins/register-server-setting.model.ts [new file with mode: 0644]
shared/models/plugins/register-setting.model.ts [deleted file]

index 0fbd651603c902b2e9282d374bb56d5f3168f2d7..569d9848256256c465a0861aee4d5c6084005792 100644 (file)
@@ -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
index 51f086a93fcdb951ae71eb71f9d0e7b084c11e95..bfcaec011e41ef7bc3028a33ea201934d7061718 100644 (file)
@@ -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)))
   }
 
index 5d180e5a0197ac5e68176f5cf88e71d7403d7911..e4a73de81d2de717f0823b3a60ff7c3a56025bc1 100644 (file)
@@ -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
index de58a7350b37abffbdb67894b86af12a9af02b5b..86384ee27bb95eb569939cb8a983f2f58037af2e 100644 (file)
@@ -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)
 }
index a87d02c56cbaa59fae38c430b265a42b8b46991e..381a894736795777bd57197354500ead1953d8c6 100644 (file)
@@ -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)
index b3d003f451745ca99dee5d9e5983e9fb48a55750..f8b2d78c92570ef5944b9b32d183e03d6e297453 100644 (file)
@@ -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)
 
index bddb3089ef7bac784730a49e5973b9515acfc774..9570579efbe7c0ae5ad56f24bf5ac527c310ad0d 100644 (file)
@@ -1,2 +1,2 @@
-export * from './register-options.model'
+export * from './register-server-option.model'
 export * from './plugin-library.model'
index fd90a3b46dd5a1d96a1aa7e822ca63774ab9b137..5b517ee9f21f66046b351855c20a369d7a269bfd 100644 (file)
@@ -1,7 +1,7 @@
-import { RegisterOptions } from './register-options.model'
+import { RegisterServerOptions } from './register-server-option.model'
 
 export interface PluginLibrary {
-  register: (options: RegisterOptions) => Promise<any>
+  register: (options: RegisterServerOptions) => Promise<any>
 
   unregister: () => Promise<any>
 }
diff --git a/server/typings/plugins/register-options.model.ts b/server/typings/plugins/register-options.model.ts
deleted file mode 100644 (file)
index 007ef5e..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-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'
-
-export type RegisterOptions = {
-  registerHook: (options: RegisterHookOptions) => void
-
-  registerSetting: (options: RegisterSettingOptions) => void
-
-  settingsManager: PluginSettingsManager
-
-  storageManager: PluginStorageManager
-
-  peertubeHelpers: {
-    logger: typeof logger
-  }
-}
diff --git a/server/typings/plugins/register-server-option.model.ts b/server/typings/plugins/register-server-option.model.ts
new file mode 100644 (file)
index 0000000..91a06a7
--- /dev/null
@@ -0,0 +1,19 @@
+import { logger } from '../../helpers/logger'
+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 RegisterServerOptions = {
+  registerHook: (options: RegisterServerHookOptions) => void
+
+  registerSetting: (options: RegisterServerSettingOptions) => void
+
+  settingsManager: PluginSettingsManager
+
+  storageManager: PluginStorageManager
+
+  peertubeHelpers: {
+    logger: typeof logger
+  }
+}
diff --git a/shared/models/plugins/register-client-hook.model.ts b/shared/models/plugins/register-client-hook.model.ts
new file mode 100644 (file)
index 0000000..81047b2
--- /dev/null
@@ -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 (file)
index 0ed2157..0000000
+++ /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 (file)
index 0000000..746fdc3
--- /dev/null
@@ -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 (file)
index 0000000..5dea93c
--- /dev/null
@@ -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 (file)
index 429ac3a..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-export interface RegisterSettingOptions {
-  name: string
-  label: string
-  type: 'input'
-  default?: string
-}
-
-export interface RegisteredSettings {
-  settings: RegisterSettingOptions[]
-}