mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
47 lines
1.3 KiB
JavaScript
47 lines
1.3 KiB
JavaScript
var apiUtils = require("../util");
|
|
|
|
var runtimeAPI;
|
|
|
|
module.exports = {
|
|
init: function(_runtimeAPI) {
|
|
runtimeAPI = _runtimeAPI;
|
|
},
|
|
getAll: function(req,res) {
|
|
var opts = {
|
|
user: req.user,
|
|
req: apiUtils.getRequestLogObject(req)
|
|
}
|
|
if (req.get("accept") == "application/json") {
|
|
runtimeAPI.plugins.getPluginList(opts).then(function(list) {
|
|
res.json(list);
|
|
})
|
|
} else {
|
|
opts.lang = apiUtils.determineLangFromHeaders(req.acceptsLanguages());
|
|
if (/[^a-z\-\*]/i.test(opts.lang)) {
|
|
res.json({});
|
|
return;
|
|
}
|
|
runtimeAPI.plugins.getPluginConfigs(opts).then(function(configs) {
|
|
res.send(configs);
|
|
})
|
|
}
|
|
},
|
|
getCatalogs: function(req,res) {
|
|
var opts = {
|
|
user: req.user,
|
|
lang: req.query.lng,
|
|
req: apiUtils.getRequestLogObject(req)
|
|
}
|
|
if (/[^a-z\-\*]/i.test(opts.lang)) {
|
|
res.json({});
|
|
return;
|
|
}
|
|
runtimeAPI.plugins.getPluginCatalogs(opts).then(function(result) {
|
|
res.json(result);
|
|
}).catch(function(err) {
|
|
console.log(err.stack);
|
|
apiUtils.rejectHandler(req,res,err);
|
|
})
|
|
}
|
|
};
|