2024-12-20 00:48:18 +01:00
|
|
|
const { Request, Response } = require('express')
|
|
|
|
const PluginManager = require('../managers/PluginManager')
|
|
|
|
const Logger = require('../Logger')
|
|
|
|
|
|
|
|
class PluginController {
|
|
|
|
constructor() {}
|
|
|
|
|
|
|
|
/**
|
2024-12-21 21:54:43 +01:00
|
|
|
* POST: /api/plugins/:id/action
|
2024-12-20 00:48:18 +01:00
|
|
|
*
|
|
|
|
* @param {Request} req
|
|
|
|
* @param {Response} res
|
|
|
|
*/
|
|
|
|
handleAction(req, res) {
|
2024-12-21 21:54:43 +01:00
|
|
|
const pluginId = req.params.id
|
2024-12-20 00:48:18 +01:00
|
|
|
const actionName = req.body.pluginAction
|
|
|
|
const target = req.body.target
|
|
|
|
const data = req.body.data
|
2024-12-21 21:54:43 +01:00
|
|
|
Logger.info(`[PluginController] Handle plugin action ${pluginId} ${actionName} ${target}`, data)
|
|
|
|
PluginManager.onAction(pluginId, actionName, target, data)
|
2024-12-20 00:48:18 +01:00
|
|
|
res.sendStatus(200)
|
|
|
|
}
|
2024-12-21 00:21:00 +01:00
|
|
|
|
|
|
|
/**
|
2024-12-21 21:54:43 +01:00
|
|
|
* POST: /api/plugins/:id/config
|
2024-12-21 00:21:00 +01:00
|
|
|
*
|
|
|
|
* @param {*} req
|
|
|
|
* @param {*} res
|
|
|
|
*/
|
|
|
|
handleConfigSave(req, res) {
|
2024-12-21 21:54:43 +01:00
|
|
|
const pluginId = req.params.id
|
2024-12-21 00:21:00 +01:00
|
|
|
const config = req.body.config
|
2024-12-21 21:54:43 +01:00
|
|
|
Logger.info(`[PluginController] Saving config for plugin ${pluginId}`, config)
|
|
|
|
PluginManager.onConfigSave(pluginId, config)
|
2024-12-21 00:21:00 +01:00
|
|
|
res.sendStatus(200)
|
|
|
|
}
|
2024-12-20 00:48:18 +01:00
|
|
|
}
|
|
|
|
module.exports = new PluginController()
|