mirror of
https://framagit.org/les/gancio.git
synced 2025-01-31 16:42:22 +01:00
allow plugins to implements its own API, fix #283
This commit is contained in:
parent
64c9c8a0e8
commit
b3b87c3802
2 changed files with 57 additions and 39 deletions
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue