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

More defensive handling of missing filename in file node.

(in line with jshint)
This commit is contained in:
Dave C-J 2014-06-30 23:23:01 +01:00
parent c7f0f9639a
commit 045f658ef9

View File

@ -20,23 +20,19 @@ module.exports = function(RED) {
function FileNode(n) {
RED.nodes.createNode(this,n);
this.filename = n.filename;
this.filename = n.filename || "";
this.appendNewline = n.appendNewline;
this.overwriteFile = n.overwriteFile;
var node = this;
this.on("input",function(msg) {
var filename = msg.filename || this.filename;
if (filename === "") {
node.warn('No filename specified');
} else if (typeof msg.payload != "undefined") {
var data = msg.payload;
if (typeof data == "object") { data = JSON.stringify(data); }
if (typeof data == "boolean") { data = data.toString(); }
if (this.appendNewline) {
data += "\n";
}
if (this.appendNewline) { data += "\n"; }
if (msg.hasOwnProperty('delete')) {
fs.unlink(filename, function (err) {
if (err) { node.warn('Failed to delete file : '+err); }
@ -65,7 +61,7 @@ module.exports = function(RED) {
function FileInNode(n) {
RED.nodes.createNode(this,n);
this.filename = n.filename;
this.filename = n.filename || "";
this.format = n.format;
var node = this;
var options = {};
@ -74,7 +70,6 @@ module.exports = function(RED) {
}
this.on("input",function(msg) {
var filename = msg.filename || this.filename;
if (filename === "") {
node.warn('No filename specified');
} else {