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: {
@UpdatedAt
updatedAt: Date
- static listEnabledPluginsAndThemes () {
+ static listEnabledPluginsAndThemes (): Bluebird<MPlugin[]> {
const query = {
where: {
enabled: true,
return PluginModel.findAll(query)
}
- static loadByNpmName (npmName: string) {
+ static loadByNpmName (npmName: string): Bluebird<MPlugin> {
const name = this.normalizePluginName(npmName)
const type = this.getTypeFromNpmName(npmName)
}
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
})
if (options.pluginType) query.where['type'] = options.pluginType
return PluginModel
- .findAndCountAll(query)
+ .findAndCountAll<MPlugin>(query)
.then(({ rows, count }) => {
return { total: count, data: rows }
})
}
- static listInstalled () {
+ static listInstalled (): Bluebird<MPlugin[]> {
const query = {
where: {
uninstalled: false
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,