mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
commit
428bf634e9
@ -250,9 +250,13 @@ module.exports = function(RED) {
|
|||||||
this.on("input", function(msg) {
|
this.on("input", function(msg) {
|
||||||
var payload;
|
var payload;
|
||||||
if (this.serverConfig.wholemsg) {
|
if (this.serverConfig.wholemsg) {
|
||||||
|
var sess;
|
||||||
|
if (msg._session) { sess = JSON.stringify(msg._session); }
|
||||||
delete msg._session;
|
delete msg._session;
|
||||||
payload = JSON.stringify(msg);
|
payload = JSON.stringify(msg);
|
||||||
} else if (msg.hasOwnProperty("payload")) {
|
if (sess) { msg._session = JSON.parse(sess); }
|
||||||
|
}
|
||||||
|
else if (msg.hasOwnProperty("payload")) {
|
||||||
if (!Buffer.isBuffer(msg.payload)) { // if it's not a buffer make sure it's a string.
|
if (!Buffer.isBuffer(msg.payload)) { // if it's not a buffer make sure it's a string.
|
||||||
payload = RED.util.ensureString(msg.payload);
|
payload = RED.util.ensureString(msg.payload);
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
<p>You can enter a list of comma separated directories and/or files. You will
|
<p>You can enter a list of comma separated directories and/or files. You will
|
||||||
need to put quotes "..." around any that have spaces in.</p>
|
need to put quotes "..." around any that have spaces in.</p>
|
||||||
<p>On Windows you must use double back-slashes \\ in any directory names.</p>
|
<p>On Windows you must use double back-slashes \\ in any directory names.</p>
|
||||||
<p>The full filename of the file that actually changed is put into <code>msg.payload</code>,
|
<p>The full filename of the file that actually changed is put into <code>msg.payload</code> and <code>msg.filename</code>,
|
||||||
while a stringified version of the watch list is returned in <code>msg.topic</code>.</p>
|
while a stringified version of the watch list is returned in <code>msg.topic</code>.</p>
|
||||||
<p><code>msg.file</code> contains just the short filename of the file that changed.
|
<p><code>msg.file</code> contains just the short filename of the file that changed.
|
||||||
<code>msg.type</code> has the type of thing changed, usually <i>file</i> or <i>directory</i>,
|
<code>msg.type</code> has the type of thing changed, usually <i>file</i> or <i>directory</i>,
|
||||||
|
@ -18,7 +18,6 @@ module.exports = function(RED) {
|
|||||||
"use strict";
|
"use strict";
|
||||||
var Notify = require("fs.notify");
|
var Notify = require("fs.notify");
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
var sep = require("path").sep;
|
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
|
|
||||||
var getAllDirs = function (dir, filelist) {
|
var getAllDirs = function (dir, filelist) {
|
||||||
@ -52,14 +51,14 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var notifications = new Notify(node.files);
|
var notifications = new Notify(node.files);
|
||||||
notifications.on('change', function (file, event, path) {
|
notifications.on('change', function (file, event, fpath) {
|
||||||
var stat;
|
var stat;
|
||||||
try {
|
try {
|
||||||
if (fs.statSync(path).isDirectory()) { path = path + sep + file; }
|
if (fs.statSync(fpath).isDirectory()) { fpath = path.join(fpath,file); }
|
||||||
stat = fs.statSync(path);
|
stat = fs.statSync(fpath);
|
||||||
} catch(e) { }
|
} catch(e) { }
|
||||||
var type = "none";
|
var type = "none";
|
||||||
var msg = { payload:path, topic:node.p, file:file };
|
var msg = { payload:fpath, topic:node.p, file:file, filename:fpath };
|
||||||
if (stat) {
|
if (stat) {
|
||||||
if (stat.isFile()) { type = "file"; msg.size = stat.size; }
|
if (stat.isFile()) { type = "file"; msg.size = stat.size; }
|
||||||
else if (stat.isBlockDevice()) { type = "blockdevice"; }
|
else if (stat.isBlockDevice()) { type = "blockdevice"; }
|
||||||
@ -69,8 +68,8 @@ module.exports = function(RED) {
|
|||||||
else if (stat.isDirectory()) {
|
else if (stat.isDirectory()) {
|
||||||
type = "directory";
|
type = "directory";
|
||||||
if (node.recursive) {
|
if (node.recursive) {
|
||||||
notifications.add([path]);
|
notifications.add([fpath]);
|
||||||
notifications.add(getAllDirs(path));
|
notifications.add(getAllDirs(fpath));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else { type = "n/a"; }
|
else { type = "n/a"; }
|
||||||
@ -79,8 +78,8 @@ module.exports = function(RED) {
|
|||||||
node.send(msg);
|
node.send(msg);
|
||||||
});
|
});
|
||||||
|
|
||||||
notifications.on('error', function (error, path) {
|
notifications.on('error', function (error, fpath) {
|
||||||
var msg = { payload:path };
|
var msg = { payload:fpath };
|
||||||
node.error(error,msg);
|
node.error(error,msg);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -297,6 +297,8 @@
|
|||||||
<p>A <i>timeout</i> can be set to trigger sending the new message using whatever has been received so far.</p>
|
<p>A <i>timeout</i> can be set to trigger sending the new message using whatever has been received so far.</p>
|
||||||
<p>If a message is received with the <b>msg.complete</b> property set, the output message is finalised and sent.
|
<p>If a message is received with the <b>msg.complete</b> property set, the output message is finalised and sent.
|
||||||
This resets any part counts.</p>
|
This resets any part counts.</p>
|
||||||
|
<p>If a message is received with the <b>msg.reset</b> property set, the partly complete message is deleted and not sent.
|
||||||
|
This resets any part counts.</p>
|
||||||
|
|
||||||
<h4>Reduce Sequence mode</h4>
|
<h4>Reduce Sequence mode</h4>
|
||||||
<p>When configured to join in reduce mode, an expression is applied to each
|
<p>When configured to join in reduce mode, an expression is applied to each
|
||||||
|
@ -598,6 +598,7 @@ module.exports = function(RED) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (msg.hasOwnProperty("reset")) { if (inflight[partid]) { delete inflight[partId] } return; }
|
||||||
if (!inflight.hasOwnProperty(partId)) {
|
if (!inflight.hasOwnProperty(partId)) {
|
||||||
if (payloadType === 'object' || payloadType === 'merged') {
|
if (payloadType === 'object' || payloadType === 'merged') {
|
||||||
inflight[partId] = {
|
inflight[partId] = {
|
||||||
|
@ -169,7 +169,7 @@ module.exports = function(RED) {
|
|||||||
var node = this;
|
var node = this;
|
||||||
|
|
||||||
this.on("input",function(msg) {
|
this.on("input",function(msg) {
|
||||||
var filename = node.filename || msg.filename || "";
|
var filename = (node.filename || msg.filename || "").replace(/\t|\r|\n/g,'');
|
||||||
if (!node.filename) {
|
if (!node.filename) {
|
||||||
node.status({fill:"grey",shape:"dot",text:filename});
|
node.status({fill:"grey",shape:"dot",text:filename});
|
||||||
}
|
}
|
||||||
|
@ -481,7 +481,7 @@ describe('websocket Node', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should feedback', function(done) {
|
it('should NOT feedback more than once', function(done) {
|
||||||
var flow = [
|
var flow = [
|
||||||
{ id: "server", type: "websocket-listener", path: "/ws", wholemsg: "true" },
|
{ id: "server", type: "websocket-listener", path: "/ws", wholemsg: "true" },
|
||||||
{ id: "client", type: "websocket-client", path: getWsUrl("/ws"), wholemsg: "true" },
|
{ id: "client", type: "websocket-client", path: getWsUrl("/ws"), wholemsg: "true" },
|
||||||
@ -497,11 +497,13 @@ describe('websocket Node', function() {
|
|||||||
});
|
});
|
||||||
var acc = 0;
|
var acc = 0;
|
||||||
helper.getNode("output").on("input", function(msg) {
|
helper.getNode("output").on("input", function(msg) {
|
||||||
if (acc++ > 20) {
|
acc = acc + 1;
|
||||||
helper.clearFlows();
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
setTimeout( function() {
|
||||||
|
acc.should.equal(1);
|
||||||
|
helper.clearFlows();
|
||||||
|
done();
|
||||||
|
}, 250);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -140,7 +140,7 @@ describe('file Nodes', function() {
|
|||||||
var n2 = helper.getNode("helperNode1");
|
var n2 = helper.getNode("helperNode1");
|
||||||
var data = ["one", "two", "three", "four"];
|
var data = ["one", "two", "three", "four"];
|
||||||
var count = 0;
|
var count = 0;
|
||||||
|
|
||||||
n2.on("input", function (msg) {
|
n2.on("input", function (msg) {
|
||||||
try {
|
try {
|
||||||
msg.should.have.property("payload");
|
msg.should.have.property("payload");
|
||||||
@ -174,7 +174,7 @@ describe('file Nodes', function() {
|
|||||||
done(e);
|
done(e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Send two messages to the file
|
// Send two messages to the file
|
||||||
n1.receive({payload:"one"});
|
n1.receive({payload:"one"});
|
||||||
n1.receive({payload:"two"});
|
n1.receive({payload:"two"});
|
||||||
@ -193,7 +193,7 @@ describe('file Nodes', function() {
|
|||||||
var n2 = helper.getNode("helperNode1");
|
var n2 = helper.getNode("helperNode1");
|
||||||
var data = ["one", "two", "three", "four"];
|
var data = ["one", "two", "three", "four"];
|
||||||
var count = 0;
|
var count = 0;
|
||||||
|
|
||||||
n2.on("input", function (msg) {
|
n2.on("input", function (msg) {
|
||||||
try {
|
try {
|
||||||
msg.should.have.property("payload");
|
msg.should.have.property("payload");
|
||||||
@ -254,7 +254,7 @@ describe('file Nodes', function() {
|
|||||||
helper.load(fileNode, flow, function() {
|
helper.load(fileNode, flow, function() {
|
||||||
var n1 = helper.getNode("fileNode1");
|
var n1 = helper.getNode("fileNode1");
|
||||||
var n2 = helper.getNode("helperNode1");
|
var n2 = helper.getNode("helperNode1");
|
||||||
|
|
||||||
n2.on("input", function (msg) {
|
n2.on("input", function (msg) {
|
||||||
try {
|
try {
|
||||||
msg.should.have.property("payload", "fine");
|
msg.should.have.property("payload", "fine");
|
||||||
@ -286,7 +286,7 @@ describe('file Nodes', function() {
|
|||||||
helper.load(fileNode, flow, function() {
|
helper.load(fileNode, flow, function() {
|
||||||
var n1 = helper.getNode("fileNode1");
|
var n1 = helper.getNode("fileNode1");
|
||||||
var n2 = helper.getNode("helperNode1");
|
var n2 = helper.getNode("helperNode1");
|
||||||
|
|
||||||
n2.on("input", function (msg) {
|
n2.on("input", function (msg) {
|
||||||
try {
|
try {
|
||||||
var f = fs.readFileSync(fileToTest).toString();
|
var f = fs.readFileSync(fileToTest).toString();
|
||||||
@ -547,6 +547,7 @@ describe('file Nodes', function() {
|
|||||||
|
|
||||||
var resourcesDir = path.join(__dirname,"..","..","..","resources");
|
var resourcesDir = path.join(__dirname,"..","..","..","resources");
|
||||||
var fileToTest = path.join(resourcesDir,"50-file-test-file.txt");
|
var fileToTest = path.join(resourcesDir,"50-file-test-file.txt");
|
||||||
|
var fileToTest2 = "\t"+path.join(resourcesDir,"50-file-test-file.txt")+"\r\n";
|
||||||
var wait = 150;
|
var wait = 150;
|
||||||
|
|
||||||
beforeEach(function(done) {
|
beforeEach(function(done) {
|
||||||
@ -608,6 +609,27 @@ describe('file Nodes', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should read in a file ending in cr and output a utf8 string', function(done) {
|
||||||
|
var flow = [{id:"fileInNode1", type:"file in", name: "fileInNode", "filename":fileToTest2, "format":"utf8", wires:[["n2"]]},
|
||||||
|
{id:"n2", type:"helper"}];
|
||||||
|
helper.load(fileNode, flow, function() {
|
||||||
|
var n1 = helper.getNode("fileInNode1");
|
||||||
|
var n2 = helper.getNode("n2");
|
||||||
|
n2.on("input", function(msg) {
|
||||||
|
try {
|
||||||
|
msg.should.have.property('payload');
|
||||||
|
msg.payload.should.be.a.String();
|
||||||
|
msg.payload.should.have.length(40)
|
||||||
|
msg.payload.should.equal("File message line 1\nFile message line 2\n");
|
||||||
|
done();
|
||||||
|
} catch(err) {
|
||||||
|
done(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
n1.receive({payload:""});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should read in a file and output split lines with parts', function(done) {
|
it('should read in a file and output split lines with parts', function(done) {
|
||||||
var flow = [{id:"fileInNode1", type:"file in", name: "fileInNode", filename:fileToTest, format:"lines", wires:[["n2"]]},
|
var flow = [{id:"fileInNode1", type:"file in", name: "fileInNode", filename:fileToTest, format:"lines", wires:[["n2"]]},
|
||||||
{id:"n2", type:"helper"}];
|
{id:"n2", type:"helper"}];
|
||||||
|
Loading…
Reference in New Issue
Block a user