Change plugin models names
This commit is contained in:
parent
5f189c9c85
commit
9ae88819c2
14 changed files with 50 additions and 41 deletions
|
@ -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
|
||||
|
|
|
@ -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)))
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
2
server/typings/plugins/index.d.ts
vendored
2
server/typings/plugins/index.d.ts
vendored
|
@ -1,2 +1,2 @@
|
|||
export * from './register-options.model'
|
||||
export * from './register-server-option.model'
|
||||
export * from './plugin-library.model'
|
||||
|
|
|
@ -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>
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
7
shared/models/plugins/register-client-hook.model.ts
Normal file
7
shared/models/plugins/register-client-hook.model.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
import { ClientHookName } from './client-hook.model'
|
||||
|
||||
export interface RegisterClientHookOptions {
|
||||
target: ClientHookName
|
||||
handler: Function
|
||||
priority?: number
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
export interface RegisterHookOptions {
|
||||
target: string
|
||||
handler: Function
|
||||
priority?: number
|
||||
}
|
7
shared/models/plugins/register-server-hook.model.ts
Normal file
7
shared/models/plugins/register-server-hook.model.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
import { ServerHookName } from './server-hook.model'
|
||||
|
||||
export interface RegisterServerHookOptions {
|
||||
target: ServerHookName
|
||||
handler: Function
|
||||
priority?: number
|
||||
}
|
10
shared/models/plugins/register-server-setting.model.ts
Normal file
10
shared/models/plugins/register-server-setting.model.ts
Normal file
|
@ -0,0 +1,10 @@
|
|||
export interface RegisterServerSettingOptions {
|
||||
name: string
|
||||
label: string
|
||||
type: 'input'
|
||||
default?: string
|
||||
}
|
||||
|
||||
export interface RegisteredServerSettings {
|
||||
settings: RegisterServerSettingOptions[]
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
export interface RegisterSettingOptions {
|
||||
name: string
|
||||
label: string
|
||||
type: 'input'
|
||||
default?: string
|
||||
}
|
||||
|
||||
export interface RegisteredSettings {
|
||||
settings: RegisterSettingOptions[]
|
||||
}
|
Loading…
Reference in a new issue