X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fserver%2Fplugin.ts;h=d094da1f560084b9d51d39e93364941d92a0e823;hb=1ca9f7c3f7afac2af4c4c25b98426731f7e789c6;hp=ba43713f66d1d61695b6fbcae1614674ecbd8da6;hpb=6702a1b2ccd666285dee9c72b5bace641d2fce8b;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/server/plugin.ts b/server/models/server/plugin.ts index ba43713f6..d094da1f5 100644 --- a/server/models/server/plugin.ts +++ b/server/models/server/plugin.ts @@ -10,7 +10,9 @@ import { import { PluginType } from '../../../shared/models/plugins/plugin.type' import { PeerTubePlugin } from '../../../shared/models/plugins/peertube-plugin.model' import { FindAndCountOptions, json } from 'sequelize' -import { PeerTubePluginIndex } from '../../../shared/models/plugins/peertube-plugin-index.model' +import { RegisterServerSettingOptions } from '../../../shared/models/plugins/register-server-setting.model' +import * as Bluebird from 'bluebird' +import { MPlugin, MPluginFormattable } from '@server/typings/models' @DefaultScope(() => ({ attributes: { @@ -85,7 +87,7 @@ export class PluginModel extends Model { @UpdatedAt updatedAt: Date - static listEnabledPluginsAndThemes () { + static listEnabledPluginsAndThemes (): Bluebird { const query = { where: { enabled: true, @@ -96,7 +98,7 @@ export class PluginModel extends Model { return PluginModel.findAll(query) } - static loadByNpmName (npmName: string) { + static loadByNpmName (npmName: string): Bluebird { const name = this.normalizePluginName(npmName) const type = this.getTypeFromNpmName(npmName) @@ -154,8 +156,17 @@ export class PluginModel extends Model { } return PluginModel.findOne(query) - .then((c: any) => { + .then((c: any) => { if (!c) return undefined + const value = c.value + + if (typeof value === 'string' && value.startsWith('{')) { + try { + return JSON.parse(value) + } catch { + return value + } + } return c.value }) @@ -197,13 +208,13 @@ export class PluginModel extends Model { if (options.pluginType) query.where['type'] = options.pluginType return PluginModel - .findAndCountAll(query) + .findAndCountAll(query) .then(({ rows, count }) => { return { total: count, data: rows } }) } - static listInstalled () { + static listInstalled (): Bluebird { const query = { where: { uninstalled: false @@ -229,7 +240,20 @@ export class PluginModel extends Model { return 'peertube-plugin-' + name } - toFormattedJSON (): PeerTubePlugin { + getPublicSettings (registeredSettings: RegisterServerSettingOptions[]) { + const result: { [ name: string ]: string } = {} + const settings = this.settings || {} + + for (const r of registeredSettings) { + if (r.private !== false) continue + + result[r.name] = settings[r.name] || r.default || null + } + + return result + } + + toFormattedJSON (this: MPluginFormattable): PeerTubePlugin { return { name: this.name, type: this.type,