diff options
-rw-r--r-- | client/src/app/+admin/plugins/plugin-show-installed/plugin-show-installed.component.ts | 4 | ||||
-rw-r--r-- | client/src/app/+admin/plugins/shared/plugin-api.service.ts | 4 | ||||
-rw-r--r-- | client/src/app/core/plugins/plugin.service.ts | 6 | ||||
-rw-r--r-- | server/controllers/api/plugins.ts | 4 | ||||
-rw-r--r-- | server/lib/plugins/plugin-manager.ts | 14 | ||||
-rw-r--r-- | server/tests/api/server/plugins.ts | 4 | ||||
-rw-r--r-- | server/typings/plugins/index.d.ts | 2 | ||||
-rw-r--r-- | server/typings/plugins/plugin-library.model.ts | 4 | ||||
-rw-r--r-- | server/typings/plugins/register-server-option.model.ts (renamed from server/typings/plugins/register-options.model.ts) | 10 | ||||
-rw-r--r-- | shared/models/plugins/register-client-hook.model.ts | 7 | ||||
-rw-r--r-- | shared/models/plugins/register-hook.model.ts | 5 | ||||
-rw-r--r-- | shared/models/plugins/register-server-hook.model.ts | 7 | ||||
-rw-r--r-- | shared/models/plugins/register-server-setting.model.ts | 10 | ||||
-rw-r--r-- | shared/models/plugins/register-setting.model.ts | 10 |
14 files changed, 50 insertions, 41 deletions
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' | |||
6 | import { ActivatedRoute } from '@angular/router' | 6 | import { ActivatedRoute } from '@angular/router' |
7 | import { Subscription } from 'rxjs' | 7 | import { Subscription } from 'rxjs' |
8 | import { map, switchMap } from 'rxjs/operators' | 8 | import { map, switchMap } from 'rxjs/operators' |
9 | import { RegisterSettingOptions } from '@shared/models/plugins/register-setting.model' | ||
10 | import { BuildFormArgument, FormReactive, FormValidatorService } from '@app/shared' | 9 | import { BuildFormArgument, FormReactive, FormValidatorService } from '@app/shared' |
10 | import { RegisterServerSettingOptions } from '@shared/models/plugins/register-server-setting.model' | ||
11 | 11 | ||
12 | @Component({ | 12 | @Component({ |
13 | selector: 'my-plugin-show-installed', | 13 | selector: 'my-plugin-show-installed', |
@@ -16,7 +16,7 @@ import { BuildFormArgument, FormReactive, FormValidatorService } from '@app/shar | |||
16 | }) | 16 | }) |
17 | export class PluginShowInstalledComponent extends FormReactive implements OnInit, OnDestroy { | 17 | export class PluginShowInstalledComponent extends FormReactive implements OnInit, OnDestroy { |
18 | plugin: PeerTubePlugin | 18 | plugin: PeerTubePlugin |
19 | registeredSettings: RegisterSettingOptions[] = [] | 19 | registeredSettings: RegisterServerSettingOptions[] = [] |
20 | pluginTypeLabel: string | 20 | pluginTypeLabel: string |
21 | 21 | ||
22 | private sub: Subscription | 22 | 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' | |||
10 | import { PeerTubePlugin } from '@shared/models/plugins/peertube-plugin.model' | 10 | import { PeerTubePlugin } from '@shared/models/plugins/peertube-plugin.model' |
11 | import { ManagePlugin } from '@shared/models/plugins/manage-plugin.model' | 11 | import { ManagePlugin } from '@shared/models/plugins/manage-plugin.model' |
12 | import { InstallOrUpdatePlugin } from '@shared/models/plugins/install-plugin.model' | 12 | import { InstallOrUpdatePlugin } from '@shared/models/plugins/install-plugin.model' |
13 | import { RegisterSettingOptions } from '@shared/models/plugins/register-setting.model' | ||
14 | import { PeerTubePluginIndex } from '@shared/models/plugins/peertube-plugin-index.model' | 13 | import { PeerTubePluginIndex } from '@shared/models/plugins/peertube-plugin-index.model' |
14 | import { RegisterServerSettingOptions } from '@shared/models/plugins/register-server-setting.model' | ||
15 | 15 | ||
16 | @Injectable() | 16 | @Injectable() |
17 | export class PluginApiService { | 17 | export class PluginApiService { |
@@ -88,7 +88,7 @@ export class PluginApiService { | |||
88 | getPluginRegisteredSettings (pluginName: string, pluginType: PluginType) { | 88 | getPluginRegisteredSettings (pluginName: string, pluginType: PluginType) { |
89 | const path = PluginApiService.BASE_APPLICATION_URL + '/' + this.nameToNpmName(pluginName, pluginType) + '/registered-settings' | 89 | const path = PluginApiService.BASE_APPLICATION_URL + '/' + this.nameToNpmName(pluginName, pluginType) + '/registered-settings' |
90 | 90 | ||
91 | return this.authHttp.get<{ settings: RegisterSettingOptions[] }>(path) | 91 | return this.authHttp.get<{ settings: RegisterServerSettingOptions[] }>(path) |
92 | .pipe(catchError(res => this.restExtractor.handleError(res))) | 92 | .pipe(catchError(res => this.restExtractor.handleError(res))) |
93 | } | 93 | } |
94 | 94 | ||
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' | |||
4 | import { ServerService } from '@app/core/server/server.service' | 4 | import { ServerService } from '@app/core/server/server.service' |
5 | import { ClientScript } from '@shared/models/plugins/plugin-package-json.model' | 5 | import { ClientScript } from '@shared/models/plugins/plugin-package-json.model' |
6 | import { environment } from '../../../environments/environment' | 6 | import { environment } from '../../../environments/environment' |
7 | import { RegisterHookOptions } from '@shared/models/plugins/register-hook.model' | ||
8 | import { ReplaySubject } from 'rxjs' | 7 | import { ReplaySubject } from 'rxjs' |
9 | import { first, shareReplay } from 'rxjs/operators' | 8 | import { first, shareReplay } from 'rxjs/operators' |
10 | import { getHookType, internalRunHook } from '@shared/core-utils/plugins/hooks' | 9 | import { getHookType, internalRunHook } from '@shared/core-utils/plugins/hooks' |
11 | import { ClientHook, ClientHookName, clientHookObject } from '@shared/models/plugins/client-hook.model' | 10 | import { ClientHook, ClientHookName, clientHookObject } from '@shared/models/plugins/client-hook.model' |
12 | import { PluginClientScope } from '@shared/models/plugins/plugin-client-scope.type' | 11 | import { PluginClientScope } from '@shared/models/plugins/plugin-client-scope.type' |
12 | import { RegisterClientHookOptions } from '@shared/models/plugins/register-client-hook.model' | ||
13 | 13 | ||
14 | interface HookStructValue extends RegisterHookOptions { | 14 | interface HookStructValue extends RegisterClientHookOptions { |
15 | plugin: ServerConfigPlugin | 15 | plugin: ServerConfigPlugin |
16 | clientScript: ClientScript | 16 | clientScript: ClientScript |
17 | } | 17 | } |
@@ -164,7 +164,7 @@ export class PluginService implements ClientHook { | |||
164 | private loadPlugin (pluginInfo: PluginInfo) { | 164 | private loadPlugin (pluginInfo: PluginInfo) { |
165 | const { plugin, clientScript } = pluginInfo | 165 | const { plugin, clientScript } = pluginInfo |
166 | 166 | ||
167 | const registerHook = (options: RegisterHookOptions) => { | 167 | const registerHook = (options: RegisterClientHookOptions) => { |
168 | if (clientHookObject[options.target] !== true) { | 168 | if (clientHookObject[options.target] !== true) { |
169 | console.error('Unknown hook %s of plugin %s. Skipping.', options.target, plugin.name) | 169 | console.error('Unknown hook %s of plugin %s. Skipping.', options.target, plugin.name) |
170 | return | 170 | 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 | |||
25 | import { logger } from '../../helpers/logger' | 25 | import { logger } from '../../helpers/logger' |
26 | import { listAvailablePluginsFromIndex } from '../../lib/plugins/plugin-index' | 26 | import { listAvailablePluginsFromIndex } from '../../lib/plugins/plugin-index' |
27 | import { PeertubePluginIndexList } from '../../../shared/models/plugins/peertube-plugin-index-list.model' | 27 | import { PeertubePluginIndexList } from '../../../shared/models/plugins/peertube-plugin-index-list.model' |
28 | import { RegisteredSettings } from '../../../shared/models/plugins/register-setting.model' | 28 | import { RegisteredServerSettings } from '../../../shared/models/plugins/register-server-setting.model' |
29 | 29 | ||
30 | const pluginRouter = express.Router() | 30 | const pluginRouter = express.Router() |
31 | 31 | ||
@@ -164,7 +164,7 @@ async function uninstallPlugin (req: express.Request, res: express.Response) { | |||
164 | function getPluginRegisteredSettings (req: express.Request, res: express.Response) { | 164 | function getPluginRegisteredSettings (req: express.Request, res: express.Response) { |
165 | const settings = PluginManager.Instance.getRegisteredSettings(req.params.npmName) | 165 | const settings = PluginManager.Instance.getRegisteredSettings(req.params.npmName) |
166 | 166 | ||
167 | const json: RegisteredSettings = { settings } | 167 | const json: RegisteredServerSettings = { settings } |
168 | 168 | ||
169 | return res.json(json) | 169 | return res.json(json) |
170 | } | 170 | } |
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' | |||
9 | import { PluginType } from '../../../shared/models/plugins/plugin.type' | 9 | import { PluginType } from '../../../shared/models/plugins/plugin.type' |
10 | import { installNpmPlugin, installNpmPluginFromDisk, removeNpmPlugin } from './yarn' | 10 | import { installNpmPlugin, installNpmPluginFromDisk, removeNpmPlugin } from './yarn' |
11 | import { outputFile, readJSON } from 'fs-extra' | 11 | import { outputFile, readJSON } from 'fs-extra' |
12 | import { RegisterSettingOptions } from '../../../shared/models/plugins/register-setting.model' | ||
13 | import { RegisterHookOptions } from '../../../shared/models/plugins/register-hook.model' | ||
14 | import { PluginSettingsManager } from '../../../shared/models/plugins/plugin-settings-manager.model' | 12 | import { PluginSettingsManager } from '../../../shared/models/plugins/plugin-settings-manager.model' |
15 | import { PluginStorageManager } from '../../../shared/models/plugins/plugin-storage-manager.model' | 13 | import { PluginStorageManager } from '../../../shared/models/plugins/plugin-storage-manager.model' |
16 | import { ServerHook, ServerHookName, serverHookObject } from '../../../shared/models/plugins/server-hook.model' | 14 | import { ServerHook, ServerHookName, serverHookObject } from '../../../shared/models/plugins/server-hook.model' |
17 | import { getHookType, internalRunHook } from '../../../shared/core-utils/plugins/hooks' | 15 | import { getHookType, internalRunHook } from '../../../shared/core-utils/plugins/hooks' |
18 | import { RegisterOptions } from '../../typings/plugins/register-options.model' | 16 | import { RegisterServerOptions } from '../../typings/plugins/register-server-option.model' |
19 | import { PluginLibrary } from '../../typings/plugins' | 17 | import { PluginLibrary } from '../../typings/plugins' |
20 | import { ClientHtml } from '../client-html' | 18 | import { ClientHtml } from '../client-html' |
19 | import { RegisterServerHookOptions } from '../../../shared/models/plugins/register-server-hook.model' | ||
20 | import { RegisterServerSettingOptions } from '../../../shared/models/plugins/register-server-setting.model' | ||
21 | 21 | ||
22 | export interface RegisteredPlugin { | 22 | export interface RegisteredPlugin { |
23 | npmName: string | 23 | npmName: string |
@@ -51,7 +51,7 @@ export class PluginManager implements ServerHook { | |||
51 | private static instance: PluginManager | 51 | private static instance: PluginManager |
52 | 52 | ||
53 | private registeredPlugins: { [ name: string ]: RegisteredPlugin } = {} | 53 | private registeredPlugins: { [ name: string ]: RegisteredPlugin } = {} |
54 | private settings: { [ name: string ]: RegisterSettingOptions[] } = {} | 54 | private settings: { [ name: string ]: RegisterServerSettingOptions[] } = {} |
55 | private hooks: { [ name: string ]: HookInformationValue[] } = {} | 55 | private hooks: { [ name: string ]: HookInformationValue[] } = {} |
56 | 56 | ||
57 | private constructor () { | 57 | private constructor () { |
@@ -391,8 +391,8 @@ export class PluginManager implements ServerHook { | |||
391 | 391 | ||
392 | // ###################### Generate register helpers ###################### | 392 | // ###################### Generate register helpers ###################### |
393 | 393 | ||
394 | private getRegisterHelpers (npmName: string, plugin: PluginModel): RegisterOptions { | 394 | private getRegisterHelpers (npmName: string, plugin: PluginModel): RegisterServerOptions { |
395 | const registerHook = (options: RegisterHookOptions) => { | 395 | const registerHook = (options: RegisterServerHookOptions) => { |
396 | if (serverHookObject[options.target] !== true) { | 396 | if (serverHookObject[options.target] !== true) { |
397 | logger.warn('Unknown hook %s of plugin %s. Skipping.', options.target, npmName) | 397 | logger.warn('Unknown hook %s of plugin %s. Skipping.', options.target, npmName) |
398 | return | 398 | return |
@@ -408,7 +408,7 @@ export class PluginManager implements ServerHook { | |||
408 | }) | 408 | }) |
409 | } | 409 | } |
410 | 410 | ||
411 | const registerSetting = (options: RegisterSettingOptions) => { | 411 | const registerSetting = (options: RegisterServerSettingOptions) => { |
412 | if (!this.settings[npmName]) this.settings[npmName] = [] | 412 | if (!this.settings[npmName]) this.settings[npmName] = [] |
413 | 413 | ||
414 | this.settings[npmName].push(options) | 414 | 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 { | |||
23 | import { PluginType } from '../../../../shared/models/plugins/plugin.type' | 23 | import { PluginType } from '../../../../shared/models/plugins/plugin.type' |
24 | import { PeerTubePluginIndex } from '../../../../shared/models/plugins/peertube-plugin-index.model' | 24 | import { PeerTubePluginIndex } from '../../../../shared/models/plugins/peertube-plugin-index.model' |
25 | import { ServerConfig } from '../../../../shared/models/server' | 25 | import { ServerConfig } from '../../../../shared/models/server' |
26 | import { RegisteredSettings } from '../../../../shared/models/plugins/register-setting.model' | ||
27 | import { PeerTubePlugin } from '../../../../shared/models/plugins/peertube-plugin.model' | 26 | import { PeerTubePlugin } from '../../../../shared/models/plugins/peertube-plugin.model' |
28 | import { User } from '../../../../shared/models/users' | 27 | import { User } from '../../../../shared/models/users' |
29 | import { PluginPackageJson } from '../../../../shared/models/plugins/plugin-package-json.model' | 28 | import { PluginPackageJson } from '../../../../shared/models/plugins/plugin-package-json.model' |
29 | import { RegisteredServerSettings } from '../../../../shared/models/plugins/register-server-setting.model' | ||
30 | 30 | ||
31 | const expect = chai.expect | 31 | const expect = chai.expect |
32 | 32 | ||
@@ -217,7 +217,7 @@ describe('Test plugins', function () { | |||
217 | npmName: 'peertube-plugin-hello-world' | 217 | npmName: 'peertube-plugin-hello-world' |
218 | }) | 218 | }) |
219 | 219 | ||
220 | const settings = (res.body as RegisteredSettings).settings | 220 | const settings = (res.body as RegisteredServerSettings).settings |
221 | 221 | ||
222 | expect(settings).to.have.length.at.least(1) | 222 | expect(settings).to.have.length.at.least(1) |
223 | 223 | ||
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 @@ | |||
1 | export * from './register-options.model' | 1 | export * from './register-server-option.model' |
2 | export * from './plugin-library.model' | 2 | 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 @@ | |||
1 | import { RegisterOptions } from './register-options.model' | 1 | import { RegisterServerOptions } from './register-server-option.model' |
2 | 2 | ||
3 | export interface PluginLibrary { | 3 | export interface PluginLibrary { |
4 | register: (options: RegisterOptions) => Promise<any> | 4 | register: (options: RegisterServerOptions) => Promise<any> |
5 | 5 | ||
6 | unregister: () => Promise<any> | 6 | unregister: () => Promise<any> |
7 | } | 7 | } |
diff --git a/server/typings/plugins/register-options.model.ts b/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 @@ | |||
1 | import { logger } from '../../helpers/logger' | 1 | import { logger } from '../../helpers/logger' |
2 | import { RegisterHookOptions } from '../../../shared/models/plugins/register-hook.model' | ||
3 | import { RegisterSettingOptions } from '../../../shared/models/plugins/register-setting.model' | ||
4 | import { PluginSettingsManager } from '../../../shared/models/plugins/plugin-settings-manager.model' | 2 | import { PluginSettingsManager } from '../../../shared/models/plugins/plugin-settings-manager.model' |
5 | import { PluginStorageManager } from '../../../shared/models/plugins/plugin-storage-manager.model' | 3 | import { PluginStorageManager } from '../../../shared/models/plugins/plugin-storage-manager.model' |
4 | import { RegisterServerHookOptions } from '../../../shared/models/plugins/register-server-hook.model' | ||
5 | import { RegisterServerSettingOptions } from '../../../shared/models/plugins/register-server-setting.model' | ||
6 | 6 | ||
7 | export type RegisterOptions = { | 7 | export type RegisterServerOptions = { |
8 | registerHook: (options: RegisterHookOptions) => void | 8 | registerHook: (options: RegisterServerHookOptions) => void |
9 | 9 | ||
10 | registerSetting: (options: RegisterSettingOptions) => void | 10 | registerSetting: (options: RegisterServerSettingOptions) => void |
11 | 11 | ||
12 | settingsManager: PluginSettingsManager | 12 | settingsManager: PluginSettingsManager |
13 | 13 | ||
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 @@ | |||
1 | import { ClientHookName } from './client-hook.model' | ||
2 | |||
3 | export interface RegisterClientHookOptions { | ||
4 | target: ClientHookName | ||
5 | handler: Function | ||
6 | priority?: number | ||
7 | } | ||
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 @@ | |||
1 | export interface RegisterHookOptions { | ||
2 | target: string | ||
3 | handler: Function | ||
4 | priority?: number | ||
5 | } | ||
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 @@ | |||
1 | import { ServerHookName } from './server-hook.model' | ||
2 | |||
3 | export interface RegisterServerHookOptions { | ||
4 | target: ServerHookName | ||
5 | handler: Function | ||
6 | priority?: number | ||
7 | } | ||
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 @@ | |||
1 | export interface RegisterServerSettingOptions { | ||
2 | name: string | ||
3 | label: string | ||
4 | type: 'input' | ||
5 | default?: string | ||
6 | } | ||
7 | |||
8 | export interface RegisteredServerSettings { | ||
9 | settings: RegisterServerSettingOptions[] | ||
10 | } | ||
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 @@ | |||
1 | export interface RegisterSettingOptions { | ||
2 | name: string | ||
3 | label: string | ||
4 | type: 'input' | ||
5 | default?: string | ||
6 | } | ||
7 | |||
8 | export interface RegisteredSettings { | ||
9 | settings: RegisterSettingOptions[] | ||
10 | } | ||