mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
@@ -19,6 +19,11 @@
|
||||
<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">
|
||||
</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">
|
||||
<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">
|
||||
@@ -46,7 +51,8 @@
|
||||
category: 'advanced-input',
|
||||
defaults: {
|
||||
name: {value:""},
|
||||
files: {value:"",required:true}
|
||||
files: {value:"",required:true},
|
||||
recursive: {value:""}
|
||||
},
|
||||
color:"BurlyWood",
|
||||
inputs:0,
|
||||
|
@@ -19,10 +19,23 @@ module.exports = function(RED) {
|
||||
var Notify = require("fs.notify");
|
||||
var fs = require("fs");
|
||||
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) {
|
||||
RED.nodes.createNode(this,n);
|
||||
|
||||
this.recursive = n.recursive || false;
|
||||
this.files = (n.files || "").split(",");
|
||||
for (var f=0; f < this.files.length; f++) {
|
||||
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);
|
||||
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);
|
||||
notifications.on('change', function (file, event, path) {
|
||||
var stat;
|
||||
@@ -41,11 +62,17 @@ module.exports = function(RED) {
|
||||
var msg = { payload:path, topic:node.p, file:file };
|
||||
if (stat) {
|
||||
if (stat.isFile()) { type = "file"; msg.size = stat.size; }
|
||||
else if (stat.isDirectory()) { type = "directory"; }
|
||||
else if (stat.isBlockDevice()) { type = "blockdevice"; }
|
||||
else if (stat.isCharacterDevice()) { type = "characterdevice"; }
|
||||
else if (stat.isSocket()) { type = "socket"; }
|
||||
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"; }
|
||||
}
|
||||
msg.type = type;
|
||||
|
Reference in New Issue
Block a user