new backend plugin system!

This commit is contained in:
lesion
2021-12-02 12:39:55 +01:00
parent d43cfbd6f9
commit fcd4428c6b
3 changed files with 58 additions and 2 deletions

View File

@@ -106,6 +106,30 @@ const settingsController = {
}
})
}
const plugins_path = path.resolve(process.env.cwd || '', 'plugins')
if (fs.existsSync(plugins_path)) {
const notifier = require('../../notifier')
const pluginsFile = fs.readdirSync(plugins_path).filter(e => path.extname(e).toLowerCase() === '.js')
pluginsFile.forEach( pluginFile => {
log.info(`Loading plugin ${pluginFile}`)
try {
const plugin = require(path.resolve(plugins_path, pluginFile))
plugin.load({ settings: settingsController.settings })
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)
}
} catch (e) {
log.error(e)
}
})
}
},
async set (key, value, is_secret = false) {