aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-07-12 11:39:58 +0200
committerChocobozzz <chocobozzz@cpy.re>2019-07-24 10:58:16 +0200
commitb5f919ac8eb2a1c20e26582fdfd377d687710d8f (patch)
tree5ec28be6f750f54bba560803ddba681103c2d82e /server/models
parent8d2be0ed7bb87283a1ec98609df6b82d83db706a (diff)
downloadPeerTube-b5f919ac8eb2a1c20e26582fdfd377d687710d8f.tar.gz
PeerTube-b5f919ac8eb2a1c20e26582fdfd377d687710d8f.tar.zst
PeerTube-b5f919ac8eb2a1c20e26582fdfd377d687710d8f.zip
WIP plugins: update plugin
Diffstat (limited to 'server/models')
-rw-r--r--server/models/server/plugin.ts32
1 files changed, 23 insertions, 9 deletions
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 @@
1import { AllowNull, Column, CreatedAt, DataType, DefaultScope, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' 1import { AllowNull, Column, CreatedAt, DataType, DefaultScope, Is, Model, Table, UpdatedAt } from 'sequelize-typescript'
2import { getSort, throwIfNotValid } from '../utils' 2import { getSort, throwIfNotValid } from '../utils'
3import { 3import {
4 isPluginDescriptionValid, isPluginHomepage, 4 isPluginDescriptionValid,
5 isPluginHomepage,
5 isPluginNameValid, 6 isPluginNameValid,
6 isPluginTypeValid, 7 isPluginTypeValid,
7 isPluginVersionValid 8 isPluginVersionValid
@@ -42,6 +43,11 @@ export class PluginModel extends Model<PluginModel> {
42 @Column 43 @Column
43 version: string 44 version: string
44 45
46 @AllowNull(true)
47 @Is('PluginLatestVersion', value => throwIfNotValid(value, isPluginVersionValid, 'version'))
48 @Column
49 latestVersion: string
50
45 @AllowNull(false) 51 @AllowNull(false)
46 @Column 52 @Column
47 enabled: boolean 53 enabled: boolean
@@ -103,27 +109,28 @@ export class PluginModel extends Model<PluginModel> {
103 return PluginModel.findOne(query) 109 return PluginModel.findOne(query)
104 } 110 }
105 111
106 static getSetting (pluginName: string, settingName: string) { 112 static getSetting (pluginName: string, pluginType: PluginType, settingName: string) {
107 const query = { 113 const query = {
108 attributes: [ 'settings' ], 114 attributes: [ 'settings' ],
109 where: { 115 where: {
110 name: pluginName 116 name: pluginName,
117 type: pluginType
111 } 118 }
112 } 119 }
113 120
114 return PluginModel.findOne(query) 121 return PluginModel.findOne(query)
115 .then(p => p.settings) 122 .then(p => {
116 .then(settings => { 123 if (!p || !p.settings) return undefined
117 if (!settings) return undefined
118 124
119 return settings[settingName] 125 return p.settings[settingName]
120 }) 126 })
121 } 127 }
122 128
123 static setSetting (pluginName: string, settingName: string, settingValue: string) { 129 static setSetting (pluginName: string, pluginType: PluginType, settingName: string, settingValue: string) {
124 const query = { 130 const query = {
125 where: { 131 where: {
126 name: pluginName 132 name: pluginName,
133 type: pluginType
127 } 134 }
128 } 135 }
129 136
@@ -171,11 +178,18 @@ export class PluginModel extends Model<PluginModel> {
171 : PluginType.THEME 178 : PluginType.THEME
172 } 179 }
173 180
181 static buildNpmName (name: string, type: PluginType) {
182 if (type === PluginType.THEME) return 'peertube-theme-' + name
183
184 return 'peertube-plugin-' + name
185 }
186
174 toFormattedJSON (): PeerTubePlugin { 187 toFormattedJSON (): PeerTubePlugin {
175 return { 188 return {
176 name: this.name, 189 name: this.name,
177 type: this.type, 190 type: this.type,
178 version: this.version, 191 version: this.version,
192 latestVersion: this.latestVersion,
179 enabled: this.enabled, 193 enabled: this.enabled,
180 uninstalled: this.uninstalled, 194 uninstalled: this.uninstalled,
181 peertubeEngine: this.peertubeEngine, 195 peertubeEngine: this.peertubeEngine,