aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
Diffstat (limited to 'server/models')
-rw-r--r--server/models/server/plugin.ts28
1 files changed, 24 insertions, 4 deletions
diff --git a/server/models/server/plugin.ts b/server/models/server/plugin.ts
index 059a442de..60abaec65 100644
--- a/server/models/server/plugin.ts
+++ b/server/models/server/plugin.ts
@@ -1,7 +1,7 @@
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, 4 isPluginDescriptionValid, isPluginHomepage,
5 isPluginNameValid, 5 isPluginNameValid,
6 isPluginTypeValid, 6 isPluginTypeValid,
7 isPluginVersionValid 7 isPluginVersionValid
@@ -20,7 +20,7 @@ import { FindAndCountOptions } from 'sequelize'
20 tableName: 'plugin', 20 tableName: 'plugin',
21 indexes: [ 21 indexes: [
22 { 22 {
23 fields: [ 'name' ], 23 fields: [ 'name', 'type' ],
24 unique: true 24 unique: true
25 } 25 }
26 ] 26 ]
@@ -59,6 +59,11 @@ export class PluginModel extends Model<PluginModel> {
59 @Column 59 @Column
60 description: string 60 description: string
61 61
62 @AllowNull(false)
63 @Is('PluginHomepage', value => throwIfNotValid(value, isPluginHomepage, 'homepage'))
64 @Column
65 homepage: string
66
62 @AllowNull(true) 67 @AllowNull(true)
63 @Column(DataType.JSONB) 68 @Column(DataType.JSONB)
64 settings: any 69 settings: any
@@ -84,10 +89,14 @@ export class PluginModel extends Model<PluginModel> {
84 return PluginModel.findAll(query) 89 return PluginModel.findAll(query)
85 } 90 }
86 91
87 static load (pluginName: string) { 92 static loadByNpmName (npmName: string) {
93 const name = this.normalizePluginName(npmName)
94 const type = this.getTypeFromNpmName(npmName)
95
88 const query = { 96 const query = {
89 where: { 97 where: {
90 name: pluginName 98 name,
99 type
91 } 100 }
92 } 101 }
93 102
@@ -150,6 +159,16 @@ export class PluginModel extends Model<PluginModel> {
150 }) 159 })
151 } 160 }
152 161
162 static normalizePluginName (name: string) {
163 return name.replace(/^peertube-((theme)|(plugin))-/, '')
164 }
165
166 static getTypeFromNpmName (npmName: string) {
167 return npmName.startsWith('peertube-plugin-')
168 ? PluginType.PLUGIN
169 : PluginType.THEME
170 }
171
153 toFormattedJSON (): PeerTubePlugin { 172 toFormattedJSON (): PeerTubePlugin {
154 return { 173 return {
155 name: this.name, 174 name: this.name,
@@ -159,6 +178,7 @@ export class PluginModel extends Model<PluginModel> {
159 uninstalled: this.uninstalled, 178 uninstalled: this.uninstalled,
160 peertubeEngine: this.peertubeEngine, 179 peertubeEngine: this.peertubeEngine,
161 description: this.description, 180 description: this.description,
181 homepage: this.homepage,
162 settings: this.settings, 182 settings: this.settings,
163 createdAt: this.createdAt, 183 createdAt: this.createdAt,
164 updatedAt: this.updatedAt 184 updatedAt: this.updatedAt