allow plugins to implements its own API, fix #283

This commit is contained in:
lesion 2023-06-22 13:48:41 +02:00
parent 64c9c8a0e8
commit b3b87c3802
No known key found for this signature in database
GPG key ID: 352918250B012177
2 changed files with 57 additions and 39 deletions

View file

@ -32,6 +32,22 @@ const pluginController = {
res.json()
},
async routeAPI (req, res, next) {
const pluginName = req.params.plugin
const plugin = pluginController.plugins.find(p => p.configuration.name === pluginName)
if (!plugin) {
log.warn(`Plugin ${pluginName} not found`)
return res.sendStatus(404)
}
if (typeof plugin.routeAPI !== 'function') {
log.warn(`Plugin ${pluginName} does not expose a 'routeAPI' function`)
return res.sendStatus(404)
}
return plugin.routeAPI(req, res, next)
},
async testPlugin (req, res) {
const pluginName = req.params.plugin
const plugin = pluginController.plugins.find(p => p.configuration.name === pluginName)

View file

@ -222,6 +222,8 @@ module.exports = () => {
api.post('/plugin/test/:plugin', isAdmin, pluginController.testPlugin)
api.put('/plugin/:plugin', isAdmin, pluginController.togglePlugin)
api.use('/plugin/:plugin', pluginController.routeAPI)
// OAUTH
api.get('/clients', isAuth, oauthController.getClients)
api.get('/client/:client_id', isAuth, oauthController.getClient)