mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Fix logic so defined msg.payload is not prereq for delete.
This commit is contained in:
parent
0111ab8901
commit
72dcb53d23
@ -28,34 +28,31 @@ module.exports = function(RED) {
|
|||||||
var filename = msg.filename || this.filename;
|
var filename = msg.filename || this.filename;
|
||||||
if (filename === "") {
|
if (filename === "") {
|
||||||
node.warn('No filename specified');
|
node.warn('No filename specified');
|
||||||
|
} else if (msg.hasOwnProperty('delete')) {
|
||||||
|
fs.unlink(filename, function (err) {
|
||||||
|
if (err) { node.warn('Failed to delete file : '+err); }
|
||||||
|
//console.log('Deleted file",filename);
|
||||||
|
});
|
||||||
} else if (typeof msg.payload != "undefined") {
|
} else if (typeof msg.payload != "undefined") {
|
||||||
if (msg.hasOwnProperty('delete')) {
|
var data = msg.payload;
|
||||||
fs.unlink(filename, function (err) {
|
if (typeof data == "object") {
|
||||||
if (err) { node.warn('Failed to delete file : '+err); }
|
if (!Buffer.isBuffer(data)) {
|
||||||
//console.log('Deleted file",filename);
|
data = JSON.stringify(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (typeof data == "boolean") { data = data.toString(); }
|
||||||
|
if ((this.appendNewline)&&(!Buffer.isBuffer(data))) { data += "\n"; }
|
||||||
|
if (this.overwriteFile) {
|
||||||
|
fs.writeFile(filename, data, function (err) {
|
||||||
|
if (err) { node.warn('Failed to write to file : '+err); }
|
||||||
|
//console.log('Message written to file',filename);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var data = msg.payload;
|
fs.appendFile(filename, data, function (err) {
|
||||||
if (typeof data == "object") {
|
if (err) { node.warn('Failed to append to file : '+err); }
|
||||||
if (!Buffer.isBuffer(data)) {
|
//console.log('Message appended to file',filename);
|
||||||
data = JSON.stringify(data);
|
});
|
||||||
}
|
|
||||||
}
|
|
||||||
if (typeof data == "boolean") { data = data.toString(); }
|
|
||||||
if ((this.appendNewline)&&(!Buffer.isBuffer(data))) { data += "\n"; }
|
|
||||||
if (this.overwriteFile) {
|
|
||||||
fs.writeFile(filename, data, function (err) {
|
|
||||||
if (err) { node.warn('Failed to write to file : '+err); }
|
|
||||||
//console.log('Message written to file',filename);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
fs.appendFile(filename, data, function (err) {
|
|
||||||
if (err) { node.warn('Failed to append to file : '+err); }
|
|
||||||
//console.log('Message appended to file',filename);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user