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

Added node warnings when message properties override set node properties

This commit is contained in:
Anna Thomas 2014-11-03 13:41:45 +00:00
parent 9f925140c9
commit 069a47f35a
6 changed files with 44 additions and 15 deletions

View File

@ -118,8 +118,7 @@
<script type="text/x-red" data-help-name="http request">
<p>Provides a node for making http requests.</p>
<p>The URL and HTTP method can be configured in the node, but also
overridden by the incoming message:
<p>The URL and HTTP method can be configured in the node, if they are left blank they should be set in an incoming message on <code>msg.url</code> and <code>msg.method</code>:</p>
<ul>
<li><code>url</code>, if set, is used as the url of the request. Must start with http: or https:</li>
<li><code>method</code>, if set, is used as the HTTP method of the request.

View File

@ -66,9 +66,9 @@ module.exports = function(RED) {
} else {
node.send({req:req,res:res});
}
}
};
var corsHandler = function(req,res,next) { next(); }
var corsHandler = function(req,res,next) { next(); };
if (RED.settings.httpNodeCors) {
corsHandler = cors(RED.settings.httpNodeCors);
@ -154,6 +154,9 @@ module.exports = function(RED) {
node.status({fill:"blue",shape:"dot",text:"requesting"});
var url;
if (msg.url) {
if (n.url) {
node.warn("Deprecated: msg properties should not override set node properties. See bit.ly/nr-override-msg-props");
}
url = msg.url;
} else if (isTemplatedUrl) {
url = mustache.render(nodeUrl,msg);
@ -165,7 +168,15 @@ module.exports = function(RED) {
url = "http://"+url;
}
var method = (msg.method||nodeMethod).toUpperCase();
var method;
if (msg.method) {
if (n.method) {
node.warn("Deprecated: msg properties should not override set node properties. See bit.ly/nr-override-msg-props");
}
method = msg.method.toUpperCase();
} else {
method = nodeMethod.toUpperCase();
}
//node.log(method+" : "+url);
var opts = urllib.parse(url);
opts.method = method;
@ -240,4 +251,4 @@ module.exports = function(RED) {
password: {type: "password"}
}
});
}
};

View File

@ -70,8 +70,8 @@
<script type="text/x-red" data-help-name="e-mail">
<p>Sends the <b>msg.payload</b> as an email, with a subject of <b>msg.topic</b>.</p>
<p>The default message recipient can be configured in the node, if it is left blank it should be set in an incoming message on <b>msg.to</b>.</p>
<!-- <p>It sends the message to the configured recipient <i>only</i>.</p> -->
<p>You may dynamically overide the default recipient by setting a <b>msg.to</b> property.</p>
<!-- <p><b>msg.topic</b> is used to set the subject of the email, and <b>msg.payload</b> is the body text.</p> -->
</script>

View File

@ -72,6 +72,9 @@ module.exports = function(RED) {
if (smtpTransport) {
node.status({fill:"blue",shape:"dot",text:"sending"});
var payload = RED.util.ensureString(msg.payload);
if (msg.to && node.name) {
node.warn("Deprecated: msg properties should not override set node properties. See bit.ly/nr-override-msg-props");
}
smtpTransport.sendMail({
from: node.userid, // sender address
to: msg.to || node.name, // comma separated list of addressees
@ -243,4 +246,4 @@ module.exports = function(RED) {
global: { type:"boolean"}
}
});
}
};

View File

@ -37,7 +37,7 @@
<script type="text/x-red" data-help-name="file">
<p>Writes <b>msg.payload</b> to the file specified, e.g. to create a log.</p>
<p>The filename can be overridden by the <b>msg.filename</b> property of the incoming message.</p>
<p>The filename can be configured in the node, if left blank it should be set in an incoming message on <b>msg.filename</b>.</p>
<p>A newline is added to every message. But this can be turned off if required, for example, to allow binary files to be written.</p>
<p>The default behaviour is to append to the file. This can be changed to overwrite the file each time, for example if you want to output a "static" web page or report.</p>
<p>If a <b>msg.delete</b> property exists then the file will be deleted instead.</p>
@ -63,7 +63,7 @@
<script type="text/x-red" data-help-name="file in">
<p>Reads the specified file and sends the content as <b>msg.payload</b>, and the filename as <b>msg.filename</b>.</p>
<p>The filename can be overridden by the <b>msg.filename</b> property of the incoming message.</p>
<p>The filename can be configured in the node, if left blank it should be set in an incoming message on <b>msg.filename</b>.</p>
</script>
<script type="text/javascript">

View File

@ -25,7 +25,15 @@ module.exports = function(RED) {
this.overwriteFile = n.overwriteFile;
var node = this;
this.on("input",function(msg) {
var filename = msg.filename || this.filename;
var filename;
if (msg.filename) {
if (n.filename) {
node.warn("Deprecated: msg properties should not override set node properties. See bit.ly/nr-override-msg-props");
}
filename = msg.filename;
} else {
filename = this.filename;
}
if (filename === "") {
node.warn('No filename specified');
} else if (msg.hasOwnProperty('delete')) {
@ -72,7 +80,15 @@ module.exports = function(RED) {
options['encoding'] = this.format;
}
this.on("input",function(msg) {
var filename = msg.filename || this.filename;
var filename;
if (msg.filename) {
if (n.filename) {
node.warn("Deprecated: msg properties should not override set node properties. See bit.ly/nr-override-msg-props");
}
filename = msg.filename;
} else {
filename = this.filename;
}
if (filename === "") {
node.warn('No filename specified');
} else {
@ -92,4 +108,4 @@ module.exports = function(RED) {
});
}
RED.nodes.registerType("file in",FileInNode);
}
};