mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
parent
7502a2b1ff
commit
7e35c9c754
@ -39,12 +39,21 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
post: function(req,res) {
|
post: function(req,res) {
|
||||||
var version = req.get("Node-RED-API-Version")||"v1";
|
var version = req.get("Node-RED-API-Version")||"v1";
|
||||||
|
if (!/^v[12]$/.test(version)) {
|
||||||
|
log.audit({event: "flows.set",version:version,error:"invalid_api_version"},req);
|
||||||
|
res.status(400).json({code:"invalid_api_version", message:"Invalid API Version requested"});
|
||||||
|
return;
|
||||||
|
}
|
||||||
var flows = req.body;
|
var flows = req.body;
|
||||||
var deploymentType = req.get("Node-RED-Deployment-Type")||"full";
|
var deploymentType = req.get("Node-RED-Deployment-Type")||"full";
|
||||||
log.audit({event: "flows.set",type:deploymentType,version:version},req);
|
log.audit({event: "flows.set",type:deploymentType,version:version},req);
|
||||||
if (deploymentType === 'reload') {
|
if (deploymentType === 'reload') {
|
||||||
redNodes.loadFlows().then(function() {
|
redNodes.loadFlows().then(function(flowId) {
|
||||||
res.status(204).end();
|
if (version === "v1") {
|
||||||
|
res.status(204).end();
|
||||||
|
} else {
|
||||||
|
res.json({rev:flowId});
|
||||||
|
}
|
||||||
}).otherwise(function(err) {
|
}).otherwise(function(err) {
|
||||||
log.warn(log._("api.flows.error-reload",{message:err.message}));
|
log.warn(log._("api.flows.error-reload",{message:err.message}));
|
||||||
log.warn(err.stack);
|
log.warn(err.stack);
|
||||||
@ -61,17 +70,12 @@ module.exports = {
|
|||||||
return res.status(409).json({code:"version_mismatch"});
|
return res.status(409).json({code:"version_mismatch"});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (version !== 'v1') {
|
|
||||||
log.audit({event: "flows.set",version:version,error:"invalid_api_version"},req);
|
|
||||||
res.status(400).json({code:"invalid_api_version", message:"Invalid API Version requested"});
|
|
||||||
}
|
}
|
||||||
redNodes.setFlows(flowConfig,deploymentType).then(function(flowId) {
|
redNodes.setFlows(flowConfig,deploymentType).then(function(flowId) {
|
||||||
if (version === "v1") {
|
if (version === "v1") {
|
||||||
res.status(204).end();
|
res.status(204).end();
|
||||||
} else if (version === "v2") {
|
} else if (version === "v2") {
|
||||||
res.json({rev:flowId});
|
res.json({rev:flowId});
|
||||||
} else {
|
|
||||||
// TODO: invalid version
|
|
||||||
}
|
}
|
||||||
}).otherwise(function(err) {
|
}).otherwise(function(err) {
|
||||||
log.warn(log._("api.flows.error-save",{message:err.message}));
|
log.warn(log._("api.flows.error-save",{message:err.message}));
|
||||||
|
Loading…
Reference in New Issue
Block a user