From b5f919ac8eb2a1c20e26582fdfd377d687710d8f Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 12 Jul 2019 11:39:58 +0200 Subject: WIP plugins: update plugin --- server/models/server/plugin.ts | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'server/models') diff --git a/server/models/server/plugin.ts b/server/models/server/plugin.ts index 226c08342..340d49f3b 100644 --- a/server/models/server/plugin.ts +++ b/server/models/server/plugin.ts @@ -1,7 +1,8 @@ import { AllowNull, Column, CreatedAt, DataType, DefaultScope, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' import { getSort, throwIfNotValid } from '../utils' import { - isPluginDescriptionValid, isPluginHomepage, + isPluginDescriptionValid, + isPluginHomepage, isPluginNameValid, isPluginTypeValid, isPluginVersionValid @@ -42,6 +43,11 @@ export class PluginModel extends Model { @Column version: string + @AllowNull(true) + @Is('PluginLatestVersion', value => throwIfNotValid(value, isPluginVersionValid, 'version')) + @Column + latestVersion: string + @AllowNull(false) @Column enabled: boolean @@ -103,27 +109,28 @@ export class PluginModel extends Model { return PluginModel.findOne(query) } - static getSetting (pluginName: string, settingName: string) { + static getSetting (pluginName: string, pluginType: PluginType, settingName: string) { const query = { attributes: [ 'settings' ], where: { - name: pluginName + name: pluginName, + type: pluginType } } return PluginModel.findOne(query) - .then(p => p.settings) - .then(settings => { - if (!settings) return undefined + .then(p => { + if (!p || !p.settings) return undefined - return settings[settingName] + return p.settings[settingName] }) } - static setSetting (pluginName: string, settingName: string, settingValue: string) { + static setSetting (pluginName: string, pluginType: PluginType, settingName: string, settingValue: string) { const query = { where: { - name: pluginName + name: pluginName, + type: pluginType } } @@ -171,11 +178,18 @@ export class PluginModel extends Model { : PluginType.THEME } + static buildNpmName (name: string, type: PluginType) { + if (type === PluginType.THEME) return 'peertube-theme-' + name + + return 'peertube-plugin-' + name + } + toFormattedJSON (): PeerTubePlugin { return { name: this.name, type: this.type, version: this.version, + latestVersion: this.latestVersion, enabled: this.enabled, uninstalled: this.uninstalled, peertubeEngine: this.peertubeEngine, -- cgit v1.2.3