Update runtime apis to support multiple libraries

This commit is contained in:
Nick O'Leary
2019-04-25 11:32:09 +01:00
parent 5e43a02cd3
commit b581e33611
15 changed files with 553 additions and 713 deletions

View File

@@ -93,9 +93,8 @@ module.exports = {
// Library
var library = require("./library");
library.init(runtimeAPI);
editorApp.get("/library/flows",needsPermission("library.read"),library.getAll,apiUtil.errorHandler);
editorApp.get(/library\/([^\/]+)(?:$|\/(.*))/,needsPermission("library.read"),library.getEntry);
editorApp.post(/library\/([^\/]+)\/(.*)/,needsPermission("library.write"),library.saveEntry);
editorApp.get(/library\/([^\/]+)\/([^\/]+)(?:$|\/(.*))/,needsPermission("library.read"),library.getEntry);
editorApp.post(/library\/([^\/]+)\/([^\/]+)\/(.*)/,needsPermission("library.write"),library.saveEntry);
// Credentials

View File

@@ -25,23 +25,12 @@ module.exports = {
init: function(_runtimeAPI) {
runtimeAPI = _runtimeAPI;
},
getAll: function(req,res) {
var opts = {
user: req.user,
type: 'flows'
}
runtimeAPI.library.getEntries(opts).then(function(result) {
res.json(result);
}).catch(function(err) {
apiUtils.rejectHandler(req,res,err);
});
},
getEntry: function(req,res) {
var opts = {
user: req.user,
type: req.params[0],
path: req.params[1]||""
library: req.params[0],
type: req.params[1],
path: req.params[2]||""
}
runtimeAPI.library.getEntry(opts).then(function(result) {
if (typeof result === "string") {
@@ -62,8 +51,9 @@ module.exports = {
saveEntry: function(req,res) {
var opts = {
user: req.user,
type: req.params[0],
path: req.params[1]||""
library: req.params[0],
type: req.params[1],
path: req.params[2]||""
}
// TODO: horrible inconsistencies between flows and all other types
if (opts.type === "flows") {