mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Updates to sentiment, exec and range to handle missing payload properties
This commit is contained in:
@@ -23,10 +23,13 @@ module.exports = function(RED) {
|
||||
var node = this;
|
||||
|
||||
this.on("input", function(msg) {
|
||||
sentiment(msg.payload, msg.overrides || null, function (err, result) {
|
||||
msg.sentiment = result;
|
||||
node.send(msg);
|
||||
});
|
||||
if (msg.hasOwnProperty("payload")) {
|
||||
sentiment(msg.payload, msg.overrides || null, function (err, result) {
|
||||
msg.sentiment = result;
|
||||
node.send(msg);
|
||||
});
|
||||
}
|
||||
else { node.send(msg); } // If no payload - just pass it on.
|
||||
});
|
||||
}
|
||||
RED.nodes.registerType("sentiment",SentimentNode);
|
||||
|
@@ -66,7 +66,7 @@ module.exports = function(RED) {
|
||||
}
|
||||
else {
|
||||
var cl = node.cmd;
|
||||
if ((node.addpay === true) && (msg.payload.trim() !== "")) { cl += " "+msg.payload; }
|
||||
if ((node.addpay === true) && ((msg.payload || "").trim() !== "")) { cl += " "+msg.payload; }
|
||||
if (node.append.trim() !== "") { cl += " "+node.append; }
|
||||
if (RED.settings.verbose) { node.log(cl); }
|
||||
var child = exec(cl, {encoding: 'binary', maxBuffer:10000000}, function (error, stdout, stderr) {
|
||||
|
@@ -27,21 +27,24 @@ module.exports = function(RED) {
|
||||
var node = this;
|
||||
|
||||
this.on('input', function (msg) {
|
||||
var n = Number(msg.payload);
|
||||
if (!isNaN(n)) {
|
||||
if (node.action == "clamp") {
|
||||
if (n < node.minin) { n = node.minin; }
|
||||
if (n > node.maxin) { n = node.maxin; }
|
||||
if (msg.hasOwnProperty("payload")) {
|
||||
var n = Number(msg.payload);
|
||||
if (!isNaN(n)) {
|
||||
if (node.action == "clamp") {
|
||||
if (n < node.minin) { n = node.minin; }
|
||||
if (n > node.maxin) { n = node.maxin; }
|
||||
}
|
||||
if (node.action == "roll") {
|
||||
if (n >= node.maxin) { n = (n - node.minin) % (node.maxin - node.minin) + node.minin; }
|
||||
if (n < node.minin) { n = (n - node.minin) % (node.maxin - node.minin) + node.maxin; }
|
||||
}
|
||||
msg.payload = ((n - node.minin) / (node.maxin - node.minin) * (node.maxout - node.minout)) + node.minout;
|
||||
if (node.round) { msg.payload = Math.round(msg.payload); }
|
||||
node.send(msg);
|
||||
}
|
||||
if (node.action == "roll") {
|
||||
if (n >= node.maxin) { n = (n - node.minin) % (node.maxin - node.minin) + node.minin; }
|
||||
if (n < node.minin) { n = (n - node.minin) % (node.maxin - node.minin) + node.maxin; }
|
||||
}
|
||||
msg.payload = ((n - node.minin) / (node.maxin - node.minin) * (node.maxout - node.minout)) + node.minout;
|
||||
if (node.round) { msg.payload = Math.round(msg.payload); }
|
||||
node.send(msg);
|
||||
else { node.log("Not a number: "+msg.payload); }
|
||||
}
|
||||
else { node.log("Not a number: "+msg.payload); }
|
||||
else { node.send(msg); } // If no payload - just pass it on.
|
||||
});
|
||||
}
|
||||
RED.nodes.registerType("range", RangeNode);
|
||||
|
Reference in New Issue
Block a user