import { RegisterSettingOptions } from '../../../shared/models/plugins/register-setting.model'
import { RegisterHookOptions } from '../../../shared/models/plugins/register-hook.model'
import { PluginSettingsManager } from '../../../shared/models/plugins/plugin-settings-manager.model'
+import { PluginStorageManager } from '../../../shared/models/plugins/plugin-storage-manager.model'
export interface RegisteredPlugin {
npmName: string
setSetting: (name: string, value: string) => PluginModel.setSetting(plugin.name, plugin.type, name, value)
}
+ const storageManager: PluginStorageManager = {
+ getData: (key: string) => PluginModel.getData(plugin.name, plugin.type, key),
+
+ storeData: (key: string, data: any) => PluginModel.storeData(plugin.name, plugin.type, key, data)
+ }
+
const library: PluginLibrary = require(join(pluginPath, packageJSON.library))
if (!isLibraryCodeValid(library)) {
throw new Error('Library code is not valid (miss register or unregister function)')
}
- library.register({ registerHook, registerSetting, settingsManager })
+ library.register({
+ registerHook,
+ registerSetting,
+ settingsManager,
+ storageManager
+ })
logger.info('Add plugin %s CSS to global file.', npmName)
} from '../../helpers/custom-validators/plugins'
import { PluginType } from '../../../shared/models/plugins/plugin.type'
import { PeerTubePlugin } from '../../../shared/models/plugins/peertube-plugin.model'
-import { FindAndCountOptions } from 'sequelize'
+import { FindAndCountOptions, json } from 'sequelize'
@DefaultScope(() => ({
attributes: {
.then(() => undefined)
}
+ static getData (pluginName: string, pluginType: PluginType, key: string) {
+ const query = {
+ raw: true,
+ attributes: [ [ json('storage.' + key), 'value' ] as any ], // FIXME: typings
+ where: {
+ name: pluginName,
+ type: pluginType
+ }
+ }
+
+ return PluginModel.findOne(query)
+ .then((c: any) => {
+ if (!c) return undefined
+
+ return c.value
+ })
+ }
+
+ static storeData (pluginName: string, pluginType: PluginType, key: string, data: any) {
+ const query = {
+ where: {
+ name: pluginName,
+ type: pluginType
+ }
+ }
+
+ const toSave = {
+ [`storage.${key}`]: data
+ }
+
+ return PluginModel.update(toSave, query)
+ .then(() => undefined)
+ }
+
static listForApi (options: {
type?: PluginType,
uninstalled?: boolean,
--- /dev/null
+import * as Bluebird from 'bluebird'
+
+export interface PluginStorageManager {
+ getData: (key: string) => Bluebird<string>
+
+ storeData: (key: string, data: any) => Bluebird<any>
+}
import { RegisterHookOptions } from './register-hook.model'
import { RegisterSettingOptions } from './register-setting.model'
import { PluginSettingsManager } from './plugin-settings-manager.model'
+import { PluginStorageManager } from './plugin-storage-manager.model'
export type RegisterOptions = {
registerHook: (options: RegisterHookOptions) => void
registerSetting: (options: RegisterSettingOptions) => void
settingsManager: PluginSettingsManager
+
+ storageManager: PluginStorageManager
}