mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Update runtime apis to support multiple libraries
This commit is contained in:
@@ -29,6 +29,7 @@ var api = module.exports = {
|
||||
* Gets an entry from the library.
|
||||
* @param {Object} opts
|
||||
* @param {User} opts.user - the user calling the api
|
||||
* @param {String} opts.library - the library
|
||||
* @param {String} opts.type - the type of entry
|
||||
* @param {String} opts.path - the path of the entry
|
||||
* @return {Promise<String|Object>} - resolves when complete
|
||||
@@ -36,12 +37,12 @@ var api = module.exports = {
|
||||
*/
|
||||
getEntry: function(opts) {
|
||||
return new Promise(function(resolve,reject) {
|
||||
runtime.library.getEntry(opts.type,opts.path).then(function(result) {
|
||||
runtime.log.audit({event: "library.get",type:opts.type,path:opts.path});
|
||||
runtime.library.getEntry(opts.library,opts.type,opts.path).then(function(result) {
|
||||
runtime.log.audit({event: "library.get",library:opts.library,type:opts.type,path:opts.path});
|
||||
return resolve(result);
|
||||
}).catch(function(err) {
|
||||
if (err) {
|
||||
runtime.log.warn(runtime.log._("api.library.error-load-entry",{path:opts.path,message:err.toString()}));
|
||||
runtime.log.warn(runtime.log._("api.library.error-load-entry",{library:opts.library,type:opts.type,path:opts.path,message:err.toString()}));
|
||||
if (err.code === 'forbidden') {
|
||||
err.status = 403;
|
||||
return reject(err);
|
||||
@@ -50,10 +51,10 @@ var api = module.exports = {
|
||||
} else {
|
||||
err.status = 400;
|
||||
}
|
||||
runtime.log.audit({event: "library.get",type:opts.type,path:opts.path,error:err.code});
|
||||
runtime.log.audit({event: "library.get",library:opts.library,type:opts.type,path:opts.path,error:err.code});
|
||||
return reject(err);
|
||||
}
|
||||
runtime.log.audit({event: "library.get",type:opts.type,error:"not_found"});
|
||||
runtime.log.audit({event: "library.get",library:opts.library,type:opts.type,error:"not_found"});
|
||||
var error = new Error();
|
||||
error.code = "not_found";
|
||||
error.status = 404;
|
||||
@@ -66,6 +67,7 @@ var api = module.exports = {
|
||||
* Saves an entry to the library
|
||||
* @param {Object} opts
|
||||
* @param {User} opts.user - the user calling the api
|
||||
* @param {String} opts.library - the library
|
||||
* @param {String} opts.type - the type of entry
|
||||
* @param {String} opts.path - the path of the entry
|
||||
* @param {Object} opts.meta - any meta data associated with the entry
|
||||
@@ -75,7 +77,7 @@ var api = module.exports = {
|
||||
*/
|
||||
saveEntry: function(opts) {
|
||||
return new Promise(function(resolve,reject) {
|
||||
runtime.library.saveEntry(opts.type,opts.path,opts.meta,opts.body).then(function() {
|
||||
runtime.library.saveEntry(opts.library,opts.type,opts.path,opts.meta,opts.body).then(function() {
|
||||
runtime.log.audit({event: "library.set",type:opts.type,path:opts.path});
|
||||
return resolve();
|
||||
}).catch(function(err) {
|
||||
@@ -91,30 +93,5 @@ var api = module.exports = {
|
||||
return reject(error);
|
||||
});
|
||||
})
|
||||
},
|
||||
/**
|
||||
* Returns a complete listing of all entries of a given type in the library.
|
||||
* @param {Object} opts
|
||||
* @param {User} opts.user - the user calling the api
|
||||
* @param {String} opts.type - the type of entry
|
||||
* @return {Promise<Object>} - the entry listing
|
||||
* @memberof @node-red/runtime_library
|
||||
*/
|
||||
getEntries: function(opts) {
|
||||
return new Promise(function(resolve,reject) {
|
||||
if (opts.type !== 'flows') {
|
||||
return reject(new Error("API only supports flows"));
|
||||
|
||||
}
|
||||
runtime.storage.getAllFlows().then(function(flows) {
|
||||
runtime.log.audit({event: "library.get.all",type:"flow"});
|
||||
var examples = runtime.nodes.getNodeExampleFlows();
|
||||
if (examples) {
|
||||
flows.d = flows.d||{};
|
||||
flows.d._examples_ = examples;
|
||||
}
|
||||
return resolve(flows);
|
||||
});
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user