1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Add flow reload admin api

This commit is contained in:
Nick O'Leary 2015-11-20 22:48:06 +00:00
parent 35c4a41d7b
commit 87d77efa57
3 changed files with 25 additions and 10 deletions

View File

@ -41,7 +41,8 @@
"api": {
"flows": {
"error-save": "Error saving flows: __message__"
"error-save": "Error saving flows: __message__",
"error-reload": "Error reloading flows: __message__"
},
"library": {
"error-load-entry": "Error loading library entry '__path__': __message__",

View File

@ -32,12 +32,22 @@ module.exports = {
var flows = req.body;
var deploymentType = req.get("Node-RED-Deployment-Type")||"full";
log.audit({event: "flows.set",type:deploymentType},req);
redNodes.setFlows(flows,deploymentType).then(function() {
res.status(204).end();
}).otherwise(function(err) {
log.warn(log._("api.flows.error-save",{message:err.message}));
log.warn(err.stack);
res.status(500).json({error:"unexpected_error", message:err.message});
});
if (deploymentType === 'reload') {
redNodes.loadFlows().then(function() {
res.status(204).end();
}).otherwise(function(err) {
log.warn(log._("api.flows.error-reload",{message:err.message}));
log.warn(err.stack);
res.status(500).json({error:"unexpected_error", message:err.message});
});
} else {
redNodes.setFlows(flows,deploymentType).then(function() {
res.status(204).end();
}).otherwise(function(err) {
log.warn(log._("api.flows.error-save",{message:err.message}));
log.warn(err.stack);
res.status(500).json({error:"unexpected_error", message:err.message});
});
}
}
}

View File

@ -25,6 +25,7 @@ var log = require("../log");
var promiseDir = nodeFn.lift(mkdirp);
var initialFlowLoadComplete = false;
var settings;
var flowsFile;
var flowsFullPath;
@ -191,8 +192,11 @@ var localfilesystem = {
getFlows: function() {
return when.promise(function(resolve) {
log.info(log._("storage.localfilesystem.user-dir",{path:settings.userDir}));
log.info(log._("storage.localfilesystem.flows-file",{path:flowsFullPath}));
if (!initialFlowLoadComplete) {
initialFlowLoadComplete = true;
log.info(log._("storage.localfilesystem.user-dir",{path:settings.userDir}));
log.info(log._("storage.localfilesystem.flows-file",{path:flowsFullPath}));
}
fs.readFile(flowsFullPath,'utf8',function(err,data) {
if (!err) {
return resolve(JSON.parse(data));