aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--client/src/types/register-client-option.model.ts4
-rw-r--r--server/lib/plugins/register-helpers.ts5
-rw-r--r--server/models/server/plugin.ts8
-rw-r--r--shared/models/plugins/server/managers/plugin-settings-manager.model.ts16
-rw-r--r--shared/models/plugins/server/settings/public-server.setting.ts4
5 files changed, 24 insertions, 13 deletions
diff --git a/client/src/types/register-client-option.model.ts b/client/src/types/register-client-option.model.ts
index 73f82e781..2460a7499 100644
--- a/client/src/types/register-client-option.model.ts
+++ b/client/src/types/register-client-option.model.ts
@@ -4,7 +4,7 @@ import {
4 RegisterClientRouteOptions, 4 RegisterClientRouteOptions,
5 RegisterClientSettingsScriptOptions, 5 RegisterClientSettingsScriptOptions,
6 RegisterClientVideoFieldOptions, 6 RegisterClientVideoFieldOptions,
7 ServerConfig 7 ServerConfig, SettingEntries
8} from '@shared/models' 8} from '@shared/models'
9 9
10export type RegisterClientOptions = { 10export type RegisterClientOptions = {
@@ -30,7 +30,7 @@ export type RegisterClientHelpers = {
30 30
31 getAuthHeader: () => { 'Authorization': string } | undefined 31 getAuthHeader: () => { 'Authorization': string } | undefined
32 32
33 getSettings: () => Promise<{ [ name: string ]: string }> 33 getSettings: () => Promise<SettingEntries>
34 34
35 getServerConfig: () => Promise<ServerConfig> 35 getServerConfig: () => Promise<ServerConfig>
36 36
diff --git a/server/lib/plugins/register-helpers.ts b/server/lib/plugins/register-helpers.ts
index acca9309a..d1756040a 100644
--- a/server/lib/plugins/register-helpers.ts
+++ b/server/lib/plugins/register-helpers.ts
@@ -17,6 +17,7 @@ import {
17 RegisterServerHookOptions, 17 RegisterServerHookOptions,
18 RegisterServerSettingOptions, 18 RegisterServerSettingOptions,
19 serverHookObject, 19 serverHookObject,
20 SettingsChangeCallback,
20 VideoPlaylistPrivacy, 21 VideoPlaylistPrivacy,
21 VideoPrivacy 22 VideoPrivacy
22} from '@shared/models' 23} from '@shared/models'
@@ -46,7 +47,7 @@ export class RegisterHelpers {
46 private idAndPassAuths: RegisterServerAuthPassOptions[] = [] 47 private idAndPassAuths: RegisterServerAuthPassOptions[] = []
47 private externalAuths: RegisterServerAuthExternalOptions[] = [] 48 private externalAuths: RegisterServerAuthExternalOptions[] = []
48 49
49 private readonly onSettingsChangeCallbacks: ((settings: any) => Promise<any>)[] = [] 50 private readonly onSettingsChangeCallbacks: SettingsChangeCallback[] = []
50 51
51 private readonly router: express.Router 52 private readonly router: express.Router
52 private readonly videoConstantManagerFactory: VideoConstantManagerFactory 53 private readonly videoConstantManagerFactory: VideoConstantManagerFactory
@@ -256,7 +257,7 @@ export class RegisterHelpers {
256 257
257 setSetting: (name: string, value: string) => PluginModel.setSetting(this.plugin.name, this.plugin.type, name, value), 258 setSetting: (name: string, value: string) => PluginModel.setSetting(this.plugin.name, this.plugin.type, name, value),
258 259
259 onSettingsChange: (cb: (settings: any) => Promise<any>) => this.onSettingsChangeCallbacks.push(cb) 260 onSettingsChange: (cb: SettingsChangeCallback) => this.onSettingsChangeCallbacks.push(cb)
260 } 261 }
261 } 262 }
262 263
diff --git a/server/models/server/plugin.ts b/server/models/server/plugin.ts
index 84f7a14e4..05083e3f7 100644
--- a/server/models/server/plugin.ts
+++ b/server/models/server/plugin.ts
@@ -2,7 +2,7 @@ import { FindAndCountOptions, json, QueryTypes } from 'sequelize'
2import { AllowNull, Column, CreatedAt, DataType, DefaultScope, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' 2import { AllowNull, Column, CreatedAt, DataType, DefaultScope, Is, Model, Table, UpdatedAt } from 'sequelize-typescript'
3import { MPlugin, MPluginFormattable } from '@server/types/models' 3import { MPlugin, MPluginFormattable } from '@server/types/models'
4import { AttributesOnly } from '@shared/typescript-utils' 4import { AttributesOnly } from '@shared/typescript-utils'
5import { PeerTubePlugin, PluginType, RegisterServerSettingOptions } from '../../../shared/models' 5import { PeerTubePlugin, PluginType, RegisterServerSettingOptions, SettingEntries, SettingValue } from '../../../shared/models'
6import { 6import {
7 isPluginDescriptionValid, 7 isPluginDescriptionValid,
8 isPluginHomepage, 8 isPluginHomepage,
@@ -148,7 +148,7 @@ export class PluginModel extends Model<Partial<AttributesOnly<PluginModel>>> {
148 148
149 return PluginModel.findOne(query) 149 return PluginModel.findOne(query)
150 .then(p => { 150 .then(p => {
151 const result: { [settingName: string ]: string | boolean } = {} 151 const result: SettingEntries = {}
152 152
153 for (const name of settingNames) { 153 for (const name of settingNames) {
154 if (!p || !p.settings || p.settings[name] === undefined) { 154 if (!p || !p.settings || p.settings[name] === undefined) {
@@ -166,7 +166,7 @@ export class PluginModel extends Model<Partial<AttributesOnly<PluginModel>>> {
166 }) 166 })
167 } 167 }
168 168
169 static setSetting (pluginName: string, pluginType: PluginType, settingName: string, settingValue: string) { 169 static setSetting (pluginName: string, pluginType: PluginType, settingName: string, settingValue: SettingValue) {
170 const query = { 170 const query = {
171 where: { 171 where: {
172 name: pluginName, 172 name: pluginName,
@@ -273,7 +273,7 @@ export class PluginModel extends Model<Partial<AttributesOnly<PluginModel>>> {
273 } 273 }
274 274
275 getPublicSettings (registeredSettings: RegisterServerSettingOptions[]) { 275 getPublicSettings (registeredSettings: RegisterServerSettingOptions[]) {
276 const result: { [ name: string ]: string } = {} 276 const result: SettingEntries = {}
277 const settings = this.settings || {} 277 const settings = this.settings || {}
278 278
279 for (const r of registeredSettings) { 279 for (const r of registeredSettings) {
diff --git a/shared/models/plugins/server/managers/plugin-settings-manager.model.ts b/shared/models/plugins/server/managers/plugin-settings-manager.model.ts
index 3c28c0565..b628718dd 100644
--- a/shared/models/plugins/server/managers/plugin-settings-manager.model.ts
+++ b/shared/models/plugins/server/managers/plugin-settings-manager.model.ts
@@ -1,9 +1,17 @@
1export type SettingValue = string | boolean
2
3export interface SettingEntries {
4 [settingName: string]: SettingValue
5}
6
7export type SettingsChangeCallback = (settings: SettingEntries) => Promise<any>
8
1export interface PluginSettingsManager { 9export interface PluginSettingsManager {
2 getSetting: (name: string) => Promise<string | boolean> 10 getSetting: (name: string) => Promise<SettingValue>
3 11
4 getSettings: (names: string[]) => Promise<{ [settingName: string]: string | boolean }> 12 getSettings: (names: string[]) => Promise<SettingEntries>
5 13
6 setSetting: (name: string, value: string) => Promise<any> 14 setSetting: (name: string, value: SettingValue) => Promise<any>
7 15
8 onSettingsChange: (cb: (names: string[]) => Promise<any>) => void 16 onSettingsChange: (cb: SettingsChangeCallback) => void
9} 17}
diff --git a/shared/models/plugins/server/settings/public-server.setting.ts b/shared/models/plugins/server/settings/public-server.setting.ts
index 9802c4d7d..d38e5424a 100644
--- a/shared/models/plugins/server/settings/public-server.setting.ts
+++ b/shared/models/plugins/server/settings/public-server.setting.ts
@@ -1,3 +1,5 @@
1import { SettingEntries } from '../managers/plugin-settings-manager.model'
2
1export interface PublicServerSetting { 3export interface PublicServerSetting {
2 publicSettings: { [ name: string ]: string } 4 publicSettings: SettingEntries
3} 5}