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

reverse overide behaviour on file, http and email. Node properties now

have priority. Warn user if msg.property tries to override. 
Warning should  be removed at next major verion bump.
This commit is contained in:
dceejay 2015-03-19 21:25:43 +00:00
parent df065e94b7
commit 9afb4a9315
5 changed files with 37 additions and 53 deletions

View File

@ -177,34 +177,24 @@ module.exports = function(RED) {
this.on("input",function(msg) { this.on("input",function(msg) {
var preRequestTimestamp = process.hrtime(); var preRequestTimestamp = process.hrtime();
node.status({fill:"blue",shape:"dot",text:"requesting"}); node.status({fill:"blue",shape:"dot",text:"requesting"});
var url; var url = nodeUrl || msg.url;
if (msg.url) { if (msg.url && nodeUrl && (nodeUrl !== msg.url)) { // revert change below when warning is finally removed
if (n.url && (n.url !== msg.url)) { node.warn("Warning: msg properties can no longer override set node properties. See bit.ly/nr-override-msg-props");
node.warn("Deprecated: msg properties should not override set node properties. See bit.ly/nr-override-msg-props");
} }
url = msg.url; if (isTemplatedUrl) {
} else if (isTemplatedUrl) {
url = mustache.render(nodeUrl,msg); url = mustache.render(nodeUrl,msg);
} else {
url = nodeUrl;
} }
// url must start http:// or https:// so assume http:// if not set // url must start http:// or https:// so assume http:// if not set
if (!((url.indexOf("http://")===0) || (url.indexOf("https://")===0))) { if (!((url.indexOf("http://")===0) || (url.indexOf("https://")===0))) {
url = "http://"+url; url = "http://"+url;
} }
var method; var method = nodeMethod.toUpperCase() || "GET";
if (msg.method) { // if method set in msg if (msg.method && n.method && (n.method !== "use")) { // warn if override option not set
if (n.method && (n.method !== "use")) { // warn if override option not set node.warn("Warning: msg properties can no longer override fixed node properties. Use explicit override option. See bit.ly/nr-override-msg-props");
node.warn("Deprecated: msg properties should not override fixed node properties. Use explicit override option. See bit.ly/nr-override-msg-props");
}
method = msg.method.toUpperCase(); // but use it anyway
} else {
if (n.method !== "use") {
method = nodeMethod.toUpperCase(); // otherwise use the selected method
} else { // unless they selected override
method = "GET"; // - in which case default to GET
} }
if (msg.method && n.method && (n.method === "use")) {
method = msg.method.toUpperCase(); // use the msg parameter
} }
var opts = urllib.parse(url); var opts = urllib.parse(url);
opts.method = method; opts.method = method;
@ -251,7 +241,7 @@ module.exports = function(RED) {
msg.statusCode = res.statusCode; msg.statusCode = res.statusCode;
msg.headers = res.headers; msg.headers = res.headers;
msg.payload = ""; msg.payload = "";
// msg.url = url; // revert when fully deprecated // msg.url = url; // revert when warning above finally removed
res.on('data',function(chunk) { res.on('data',function(chunk) {
msg.payload += chunk; msg.payload += chunk;
}); });

View File

@ -87,7 +87,7 @@
defaults: { defaults: {
server: {value:"smtp.gmail.com",required:true}, server: {value:"smtp.gmail.com",required:true},
port: {value:"465",required:true}, port: {value:"465",required:true},
name: {value:"",required:true}, name: {value:""},
dname: {value:""} dname: {value:""}
}, },
credentials: { credentials: {
@ -95,7 +95,6 @@
password: {type: "password"}, password: {type: "password"},
global: { type:"boolean"} global: { type:"boolean"}
}, },
inputs:1, inputs:1,
outputs:0, outputs:0,
icon: "envelope.png", icon: "envelope.png",

View File

@ -72,10 +72,10 @@ module.exports = function(RED) {
if (smtpTransport) { if (smtpTransport) {
node.status({fill:"blue",shape:"dot",text:"sending"}); node.status({fill:"blue",shape:"dot",text:"sending"});
if (msg.to && node.name && (msg.to !== node.name)) { if (msg.to && node.name && (msg.to !== node.name)) {
node.warn("Deprecated: msg properties should not override set node properties. See bit.ly/nr-override-msg-props"); node.warn("Warning: msg properties can no longer override set node properties. See bit.ly/nr-override-msg-props");
} }
var sendopts = { from: node.userid }; // sender address var sendopts = { from: node.userid }; // sender address
sendopts.to = msg.to || node.name; // comma separated list of addressees sendopts.to = node.name || msg.to; // comma separated list of addressees
sendopts.subject = msg.topic || msg.title || "Message from Node-RED"; // subject line sendopts.subject = msg.topic || msg.title || "Message from Node-RED"; // subject line
if (Buffer.isBuffer(msg.payload)) { // if it's a buffer in the payload then auto create an attachment instead if (Buffer.isBuffer(msg.payload)) { // if it's a buffer in the payload then auto create an attachment instead
sendopts.attachments = [ { content: msg.payload, filename:(msg.filename.replace(/^.*[\\\/]/, '') || "file.bin") } ]; sendopts.attachments = [ { content: msg.payload, filename:(msg.filename.replace(/^.*[\\\/]/, '') || "file.bin") } ];

View File

@ -85,7 +85,7 @@
align: "right", align: "right",
label: function() { label: function() {
if (this.overwriteFile === "delete") { return this.name||"delete "+this.filename; } if (this.overwriteFile === "delete") { return this.name||"delete "+this.filename; }
else { return this.name||this.filename; } else { return this.name||this.filename||"file"; }
}, },
labelStyle: function() { labelStyle: function() {
return this.name?"node_label_italic":""; return this.name?"node_label_italic":"";
@ -110,7 +110,7 @@
outputs:1, outputs:1,
icon: "file.png", icon: "file.png",
label: function() { label: function() {
return this.name||this.filename; return this.name||this.filename||"file";
}, },
labelStyle: function() { labelStyle: function() {
return this.name?"node_label_italic":""; return this.name?"node_label_italic":"";

View File

@ -20,29 +20,26 @@ module.exports = function(RED) {
function FileNode(n) { function FileNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.filename = n.filename || ""; this.filename = n.filename;
this.appendNewline = n.appendNewline; this.appendNewline = n.appendNewline;
this.overwriteFile = n.overwriteFile.toString(); this.overwriteFile = n.overwriteFile.toString();
var node = this; var node = this;
this.on("input",function(msg) { this.on("input",function(msg) {
var filename; var filename = this.filename || msg.filename || "";
if (msg.filename) { if (msg.filename && n.filename && (n.filename !== msg.filename)) {
if (n.filename && (n.filename !== msg.filename)) { node.warn("Warning: msg properties can no longer override set node properties. See bit.ly/nr-override-msg-props");
node.warn("Deprecated: msg properties should not override set node properties. See bit.ly/nr-override-msg-props");
} }
filename = msg.filename; if (!this.filename) {
node.status({fill:"grey",shape:"dot",text:msg.filename}); node.status({fill:"grey",shape:"dot",text:filename});
} else {
filename = this.filename;
} }
if (filename === "") { if (filename === "") {
node.warn('No filename specified'); node.warn('No filename specified');
} else if (msg.hasOwnProperty('delete')) { } else if (msg.hasOwnProperty('delete')) { // remove warning at some point in future
node.warn("Deprecated: please use specific delete option in config dialog."); node.warn("Warning: Invalid delete. Please use specific delete option in config dialog.");
fs.unlink(filename, function (err) { //fs.unlink(filename, function (err) {
if (err) { node.error('Failed to delete file : '+err,msg); } //if (err) { node.error('Failed to delete file : '+err,msg); }
}); //});
} else if (typeof msg.payload != "undefined") { } else if (msg.payload && (typeof msg.payload != "undefined")) {
var data = msg.payload; var data = msg.payload;
if ((typeof data === "object")&&(!Buffer.isBuffer(data))) { if ((typeof data === "object")&&(!Buffer.isBuffer(data))) {
data = JSON.stringify(data); data = JSON.stringify(data);
@ -80,7 +77,7 @@ module.exports = function(RED) {
function FileInNode(n) { function FileInNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.filename = n.filename || ""; this.filename = n.filename;
this.format = n.format; this.format = n.format;
var node = this; var node = this;
var options = {}; var options = {};
@ -88,14 +85,12 @@ module.exports = function(RED) {
options['encoding'] = this.format; options['encoding'] = this.format;
} }
this.on("input",function(msg) { this.on("input",function(msg) {
var filename; var filename = this.filename || msg.filename || "";
if (msg.filename) { if (msg.filename && n.filename && (n.filename !== msg.filename)) {
if (n.filename && (n.filename !== msg.filename)) { node.warn("Warning: msg properties can no longer override set node properties. See bit.ly/nr-override-msg-props");
node.warn("Deprecated: msg properties should not override set node properties. See bit.ly/nr-override-msg-props");
} }
filename = msg.filename; if (!this.filename) {
} else { node.status({fill:"grey",shape:"dot",text:filename});
filename = this.filename;
} }
if (filename === "") { if (filename === "") {
node.warn('No filename specified'); node.warn('No filename specified');