save plugin settings and toggle enable/disable

This commit is contained in:
lesion
2022-08-29 22:47:09 +02:00
parent 438780a741
commit 982db2b51d
5 changed files with 150 additions and 36 deletions

View File

@@ -5,10 +5,42 @@ const config = require('../../config')
const pluginController = {
plugins: [],
getAll (req, res, next) {
getAll(req, res, next) {
res.json(pluginController.plugins)
},
_load () {
togglePlugin(req, res, next) {
const plugin = req.params.plugin
if (this.plugins[plugin].enable) {
}
},
unloadPlugin(plugin) {
log.info('Unload plugin ' + plugin)
},
loadPlugin(pluginName) {
const plugin = this.plugins[pluginName]
if (!plugin) {
log.warn(`Plugin ${pluginName} not found`)
return
}
if (typeof plugin.onEventCreate === 'function') {
notifier.emitter.on('Create', plugin.onEventCreate)
}
if (typeof plugin.onEventDelete === 'function') {
notifier.emitter.on('Delete', plugin.onEventDelete)
}
if (typeof plugin.onEventUpdate === 'function') {
notifier.emitter.on('Update', plugin.onEventUpdate)
}
plugin.load({ settings: settingsController.settings }, settingsController.settings.plugins)
},
_load() {
const settingsController = require('./settings')
// load custom plugins
const plugins_path = config.plugins_path || path.resolve(process.env.cwd || '', 'gancio_plugins')
@@ -18,7 +50,7 @@ const pluginController = {
const plugins = fs.readdirSync(plugins_path)
.map(e => path.resolve(plugins_path, e, 'index.js'))
.filter(index => fs.existsSync(index))
plugins.forEach( pluginFile => {
plugins.forEach(pluginFile => {
try {
const plugin = require(pluginFile)
if (typeof plugin.load !== 'function') return
@@ -46,8 +78,8 @@ const pluginController = {
log.warn(`Unable to load plugin ${pluginFile}: ${String(e)}`)
}
})
}
}
}
}
module.exports = pluginController
module.exports = pluginController