mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Update file node to support Property Out
This commit is contained in:
parent
f1e54c959b
commit
4a3b224ce2
@ -1,5 +1,9 @@
|
|||||||
|
|
||||||
<script type="text/html" data-template-name="file">
|
<script type="text/html" data-template-name="file">
|
||||||
|
<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">
|
||||||
|
</div>
|
||||||
<div class="form-row node-input-filename">
|
<div class="form-row node-input-filename">
|
||||||
<label for="node-input-filename"><i class="fa fa-file"></i> <span data-i18n="file.label.filename"></span></label>
|
<label for="node-input-filename"><i class="fa fa-file"></i> <span data-i18n="file.label.filename"></span></label>
|
||||||
<input id="node-input-filename" type="text">
|
<input id="node-input-filename" type="text">
|
||||||
@ -28,14 +32,14 @@
|
|||||||
<select type="text" id="node-input-encoding" style="width: 250px;">
|
<select type="text" id="node-input-encoding" style="width: 250px;">
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</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">
|
|
||||||
</div>
|
|
||||||
<div class="form-tips"><span data-i18n="file.tip"></span></div>
|
<div class="form-tips"><span data-i18n="file.tip"></span></div>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/html" data-template-name="file in">
|
<script type="text/html" data-template-name="file in">
|
||||||
|
<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">
|
||||||
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-filename"><i class="fa fa-file"></i> <span data-i18n="file.label.filename"></span></label>
|
<label for="node-input-filename"><i class="fa fa-file"></i> <span data-i18n="file.label.filename"></span></label>
|
||||||
<input id="node-input-filename" type="text">
|
<input id="node-input-filename" type="text">
|
||||||
@ -61,8 +65,8 @@
|
|||||||
</select>
|
</select>
|
||||||
</div>
|
</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-propertyOut"><i class="fa fa-sign-out"></i> <span data-i18n="common.label.propertyOut"></span></label>
|
||||||
<input type="text" id="node-input-name">
|
<input type="text" id="node-input-propertyOut" style="width:70%;"/>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-tips"><span data-i18n="file.tip"></span></div>
|
<div class="form-tips"><span data-i18n="file.tip"></span></div>
|
||||||
</script>
|
</script>
|
||||||
@ -299,6 +303,9 @@
|
|||||||
name: {value:""},
|
name: {value:""},
|
||||||
filename: {value:"", validate: RED.validators.typedInput({ typeField: 'filenameType' }) },
|
filename: {value:"", validate: RED.validators.typedInput({ typeField: 'filenameType' }) },
|
||||||
filenameType: {value:"str"},
|
filenameType: {value:"str"},
|
||||||
|
propertyOut: {value:"payload",required:true,
|
||||||
|
validate: RED.validators.typedInput({ type: 'msg', allowUndefined: true}),
|
||||||
|
label:RED._("node-red:common.label.propertyOut")},
|
||||||
format: {value:"utf8"},
|
format: {value:"utf8"},
|
||||||
chunk: {value:false},
|
chunk: {value:false},
|
||||||
sendError: {value: false},
|
sendError: {value: false},
|
||||||
@ -345,6 +352,10 @@
|
|||||||
types: [{label:RED._("node-red:file.label.path"), value:"str", icon:""}, "msg", "jsonata", "env"],
|
types: [{label:RED._("node-red:file.label.path"), value:"str", icon:""}, "msg", "jsonata", "env"],
|
||||||
typeField: $("#node-input-filenameType")
|
typeField: $("#node-input-filenameType")
|
||||||
});
|
});
|
||||||
|
if (this.propertyOut === undefined) {
|
||||||
|
$("#node-input-propertyOut").val("payload");
|
||||||
|
}
|
||||||
|
$("#node-input-propertyOut").typedInput({default:'msg',types:['msg']});
|
||||||
if(typeof node.filenameType == 'undefined') {
|
if(typeof node.filenameType == 'undefined') {
|
||||||
//existing node AND filenameType is not set - inplace (compatible) upgrade to new typedInput
|
//existing node AND filenameType is not set - inplace (compatible) upgrade to new typedInput
|
||||||
if(node.filename == "") { //was using empty value to denote msg.filename - set typedInput to match
|
if(node.filename == "") { //was using empty value to denote msg.filename - set typedInput to match
|
||||||
|
@ -286,6 +286,7 @@ module.exports = function(RED) {
|
|||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
this.filename = n.filename;
|
this.filename = n.filename;
|
||||||
this.filenameType = n.filenameType;
|
this.filenameType = n.filenameType;
|
||||||
|
this.propertyOut = n.propertyOut || "payload";
|
||||||
this.format = n.format;
|
this.format = n.format;
|
||||||
this.chunk = false;
|
this.chunk = false;
|
||||||
this.encoding = n.encoding || "none";
|
this.encoding = n.encoding || "none";
|
||||||
@ -370,7 +371,7 @@ module.exports = function(RED) {
|
|||||||
m.topic = msg.topic;
|
m.topic = msg.topic;
|
||||||
m.filename = msg.filename;
|
m.filename = msg.filename;
|
||||||
}
|
}
|
||||||
m.payload = bits[i];
|
RED.util.setMessageProperty(m,node.propertyOut,bits[i]);
|
||||||
m.parts= {index:count, ch:ch, type:type, id:msg._msgid}
|
m.parts= {index:count, ch:ch, type:type, id:msg._msgid}
|
||||||
count += 1;
|
count += 1;
|
||||||
nodeSend(m);
|
nodeSend(m);
|
||||||
@ -386,7 +387,7 @@ module.exports = function(RED) {
|
|||||||
m.topic = msg.topic;
|
m.topic = msg.topic;
|
||||||
m.filename = msg.filename;
|
m.filename = msg.filename;
|
||||||
}
|
}
|
||||||
m.payload = chunk;
|
RED.util.setMessageProperty(m,node.propertyOut,chunk);
|
||||||
m.parts = {index:count, ch:ch, type:type, id:msg._msgid}
|
m.parts = {index:count, ch:ch, type:type, id:msg._msgid}
|
||||||
count += 1;
|
count += 1;
|
||||||
if (chunk.length < hwm) { // last chunk is smaller that high water mark = eof
|
if (chunk.length < hwm) { // last chunk is smaller that high water mark = eof
|
||||||
@ -405,7 +406,7 @@ module.exports = function(RED) {
|
|||||||
node.error(err, msg);
|
node.error(err, msg);
|
||||||
if (node.sendError) {
|
if (node.sendError) {
|
||||||
var sendMessage = RED.util.cloneMessage(msg);
|
var sendMessage = RED.util.cloneMessage(msg);
|
||||||
delete sendMessage.payload;
|
delete sendMessage[node.propertyOut];
|
||||||
sendMessage.error = err;
|
sendMessage.error = err;
|
||||||
nodeSend(sendMessage);
|
nodeSend(sendMessage);
|
||||||
}
|
}
|
||||||
@ -414,9 +415,10 @@ module.exports = function(RED) {
|
|||||||
.on('end', function() {
|
.on('end', function() {
|
||||||
if (node.chunk === false) {
|
if (node.chunk === false) {
|
||||||
if (node.format === "utf8") {
|
if (node.format === "utf8") {
|
||||||
msg.payload = decode(lines, node.encoding);
|
RED.util.setMessageProperty(m,node.propertyOut,decode(lines, node.encoding));
|
||||||
|
} else {
|
||||||
|
RED.util.setMessageProperty(m,node.propertyOut,lines);
|
||||||
}
|
}
|
||||||
else { msg.payload = lines; }
|
|
||||||
nodeSend(msg);
|
nodeSend(msg);
|
||||||
}
|
}
|
||||||
else if (node.format === "lines") {
|
else if (node.format === "lines") {
|
||||||
@ -428,7 +430,7 @@ module.exports = function(RED) {
|
|||||||
m.topic = msg.topic;
|
m.topic = msg.topic;
|
||||||
m.filename = msg.filename;
|
m.filename = msg.filename;
|
||||||
}
|
}
|
||||||
m.payload = spare;
|
RED.util.setMessageProperty(m,node.propertyOut,spare);
|
||||||
m.parts = {
|
m.parts = {
|
||||||
index: count,
|
index: count,
|
||||||
count: count + 1,
|
count: count + 1,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user