mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
parent
ada8e447cc
commit
7029541b4f
@ -19,6 +19,11 @@
|
|||||||
<label for="node-input-files"><i class="fa fa-file"></i> <span data-i18n="watch.label.files"></span></label>
|
<label for="node-input-files"><i class="fa fa-file"></i> <span data-i18n="watch.label.files"></span></label>
|
||||||
<input id="node-input-files" type="text" tabindex="1" data-i18n="[placeholder]watch.placeholder.files">
|
<input id="node-input-files" type="text" tabindex="1" data-i18n="[placeholder]watch.placeholder.files">
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label> </label>
|
||||||
|
<input type="checkbox" id="node-input-recursive" style="display:inline-block; width:auto; vertical-align:top;">
|
||||||
|
<label for="node-input-recursive" style="width:70%;"> <span data-i18n="watch.label.recursive"></span></label>
|
||||||
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
|
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
|
||||||
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
|
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
|
||||||
@ -46,7 +51,8 @@
|
|||||||
category: 'advanced-input',
|
category: 'advanced-input',
|
||||||
defaults: {
|
defaults: {
|
||||||
name: {value:""},
|
name: {value:""},
|
||||||
files: {value:"",required:true}
|
files: {value:"",required:true},
|
||||||
|
recursive: {value:""}
|
||||||
},
|
},
|
||||||
color:"BurlyWood",
|
color:"BurlyWood",
|
||||||
inputs:0,
|
inputs:0,
|
||||||
|
@ -19,10 +19,23 @@ module.exports = function(RED) {
|
|||||||
var Notify = require("fs.notify");
|
var Notify = require("fs.notify");
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
var sep = require("path").sep;
|
var sep = require("path").sep;
|
||||||
|
var path = require("path");
|
||||||
|
|
||||||
|
var getAllDirs = function (dir, filelist) {
|
||||||
|
filelist = filelist || [];
|
||||||
|
fs.readdirSync(dir).forEach(file => {
|
||||||
|
if (fs.statSync(path.join(dir, file)).isDirectory() ) {
|
||||||
|
filelist.push(path.join(dir, file));
|
||||||
|
getAllDirs(path.join(dir, file), filelist);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return filelist;
|
||||||
|
}
|
||||||
|
|
||||||
function WatchNode(n) {
|
function WatchNode(n) {
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
|
|
||||||
|
this.recursive = n.recursive || false;
|
||||||
this.files = (n.files || "").split(",");
|
this.files = (n.files || "").split(",");
|
||||||
for (var f=0; f < this.files.length; f++) {
|
for (var f=0; f < this.files.length; f++) {
|
||||||
this.files[f] = this.files[f].trim();
|
this.files[f] = this.files[f].trim();
|
||||||
@ -30,6 +43,14 @@ module.exports = function(RED) {
|
|||||||
this.p = (this.files.length === 1) ? this.files[0] : JSON.stringify(this.files);
|
this.p = (this.files.length === 1) ? this.files[0] : JSON.stringify(this.files);
|
||||||
var node = this;
|
var node = this;
|
||||||
|
|
||||||
|
if (node.recursive) {
|
||||||
|
for (var fi in node.files) {
|
||||||
|
if (node.files.hasOwnProperty(fi)) {
|
||||||
|
node.files = node.files.concat(getAllDirs( node.files[fi]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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, path) {
|
||||||
var stat;
|
var stat;
|
||||||
@ -41,11 +62,17 @@ module.exports = function(RED) {
|
|||||||
var msg = { payload:path, topic:node.p, file:file };
|
var msg = { payload:path, topic:node.p, file:file };
|
||||||
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.isDirectory()) { type = "directory"; }
|
|
||||||
else if (stat.isBlockDevice()) { type = "blockdevice"; }
|
else if (stat.isBlockDevice()) { type = "blockdevice"; }
|
||||||
else if (stat.isCharacterDevice()) { type = "characterdevice"; }
|
else if (stat.isCharacterDevice()) { type = "characterdevice"; }
|
||||||
else if (stat.isSocket()) { type = "socket"; }
|
else if (stat.isSocket()) { type = "socket"; }
|
||||||
else if (stat.isFIFO()) { type = "fifo"; }
|
else if (stat.isFIFO()) { type = "fifo"; }
|
||||||
|
else if (stat.isDirectory()) {
|
||||||
|
type = "directory";
|
||||||
|
if (node.recursive) {
|
||||||
|
notifications.add([path]);
|
||||||
|
notifications.add(getAllDirs(path));
|
||||||
|
}
|
||||||
|
}
|
||||||
else { type = "n/a"; }
|
else { type = "n/a"; }
|
||||||
}
|
}
|
||||||
msg.type = type;
|
msg.type = type;
|
||||||
|
@ -233,13 +233,14 @@
|
|||||||
"output": {
|
"output": {
|
||||||
"string": "the string",
|
"string": "the string",
|
||||||
"number": "the number",
|
"number": "the number",
|
||||||
"existing": "the existing msg.payload",
|
"existing": "the existing msg object",
|
||||||
"original": "the original msg.payload",
|
"original": "the original msg object",
|
||||||
"latest": "the latest msg.payload",
|
"latest": "the latest msg object",
|
||||||
"nothing": "nothing"
|
"nothing": "nothing"
|
||||||
},
|
},
|
||||||
"wait-reset": "wait to be reset",
|
"wait-reset": "wait to be reset",
|
||||||
"wait-for": "wait for",
|
"wait-for": "wait for",
|
||||||
|
"wait-loop": "resend it every",
|
||||||
"duration": {
|
"duration": {
|
||||||
"ms": "Milliseconds",
|
"ms": "Milliseconds",
|
||||||
"s": "Seconds",
|
"s": "Seconds",
|
||||||
@ -250,6 +251,7 @@
|
|||||||
"label": {
|
"label": {
|
||||||
"trigger": "trigger",
|
"trigger": "trigger",
|
||||||
"trigger-block": "trigger & block",
|
"trigger-block": "trigger & block",
|
||||||
|
"trigger-loop": "resend every",
|
||||||
"reset": "Reset the trigger if:",
|
"reset": "Reset the trigger if:",
|
||||||
"resetMessage":"msg.reset is set",
|
"resetMessage":"msg.reset is set",
|
||||||
"resetPayload":"msg.payload equals",
|
"resetPayload":"msg.payload equals",
|
||||||
@ -369,7 +371,8 @@
|
|||||||
},
|
},
|
||||||
"watch": {
|
"watch": {
|
||||||
"label": {
|
"label": {
|
||||||
"files": "File(s)"
|
"files": "File(s)",
|
||||||
|
"recursive": "Watch sub-directories recursively"
|
||||||
},
|
},
|
||||||
"placeholder": {
|
"placeholder": {
|
||||||
"files": "Comma-separated list of files and/or directories"
|
"files": "Comma-separated list of files and/or directories"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user