Merge pull request #1895 from node-red/Tidy-core-nodes

Tidy core nodes
This commit is contained in:
Nick O'Leary
2018-09-28 13:20:58 +01:00
committed by GitHub
8 changed files with 52 additions and 22 deletions

View File

@@ -250,9 +250,13 @@ module.exports = function(RED) {
this.on("input", function(msg) {
var payload;
if (this.serverConfig.wholemsg) {
var sess;
if (msg._session) { sess = JSON.stringify(msg._session); }
delete msg._session;
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.
payload = RED.util.ensureString(msg.payload);
}

View File

@@ -36,7 +36,7 @@
<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>
<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>
<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>,

View File

@@ -18,7 +18,6 @@ module.exports = function(RED) {
"use strict";
var Notify = require("fs.notify");
var fs = require("fs");
var sep = require("path").sep;
var path = require("path");
var getAllDirs = function (dir, filelist) {
@@ -52,14 +51,14 @@ module.exports = function(RED) {
}
var notifications = new Notify(node.files);
notifications.on('change', function (file, event, path) {
notifications.on('change', function (file, event, fpath) {
var stat;
try {
if (fs.statSync(path).isDirectory()) { path = path + sep + file; }
stat = fs.statSync(path);
if (fs.statSync(fpath).isDirectory()) { fpath = path.join(fpath,file); }
stat = fs.statSync(fpath);
} catch(e) { }
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.isFile()) { type = "file"; msg.size = stat.size; }
else if (stat.isBlockDevice()) { type = "blockdevice"; }
@@ -69,8 +68,8 @@ module.exports = function(RED) {
else if (stat.isDirectory()) {
type = "directory";
if (node.recursive) {
notifications.add([path]);
notifications.add(getAllDirs(path));
notifications.add([fpath]);
notifications.add(getAllDirs(fpath));
}
}
else { type = "n/a"; }
@@ -79,8 +78,8 @@ module.exports = function(RED) {
node.send(msg);
});
notifications.on('error', function (error, path) {
var msg = { payload:path };
notifications.on('error', function (error, fpath) {
var msg = { payload:fpath };
node.error(error,msg);
});

View File

@@ -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>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>
<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>
<p>When configured to join in reduce mode, an expression is applied to each

View File

@@ -598,6 +598,7 @@ module.exports = function(RED) {
return;
}
if (msg.hasOwnProperty("reset")) { if (inflight[partid]) { delete inflight[partId] } return; }
if (!inflight.hasOwnProperty(partId)) {
if (payloadType === 'object' || payloadType === 'merged') {
inflight[partId] = {

View File

@@ -169,7 +169,7 @@ module.exports = function(RED) {
var node = this;
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) {
node.status({fill:"grey",shape:"dot",text:filename});
}