mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
final updates to file node filename typedInput
- ensure node settings are auto updated to correct typedInput type/value - improve label - ensure str and env are considered "static" (keep stream open)
This commit is contained in:
parent
6e35a9f682
commit
99b049fe2d
@ -211,7 +211,8 @@
|
|||||||
icon: "file-out.svg",
|
icon: "file-out.svg",
|
||||||
label: function() {
|
label: function() {
|
||||||
var fn = this.filename;
|
var fn = this.filename;
|
||||||
if(this.filenameType != "str") { fn = ""; }
|
if(this.filenameType != "str" && this.filenameType != "env" ) { fn = ""; }
|
||||||
|
if(this.filenameType === "env") { fn = "env."+fn; }
|
||||||
if (this.overwriteFile === "delete") {
|
if (this.overwriteFile === "delete") {
|
||||||
return this.name||this._("file.label.deletelabel",{file:fn});
|
return this.name||this._("file.label.deletelabel",{file:fn});
|
||||||
} else {
|
} else {
|
||||||
@ -239,11 +240,25 @@
|
|||||||
types:[{ value: "str", label:"", icon:"red/images/typedInput/az.svg"}, "msg", "jsonata", "env"],
|
types:[{ value: "str", label:"", icon:"red/images/typedInput/az.svg"}, "msg", "jsonata", "env"],
|
||||||
typeField: $("#node-input-filenameType")
|
typeField: $("#node-input-filenameType")
|
||||||
});
|
});
|
||||||
if(!node.filename && !node.filenameType) {
|
if(typeof node.filenameType == 'undefined') {
|
||||||
node.filename = "filename"
|
//existing node AND filenameType is not set - inplace (compatible) upgrade to new typedInput
|
||||||
node.filenameType = "msg"
|
if(node.filename == "") { //was using empty value to denote msg.filename - set typedInput to match
|
||||||
|
node.filename = "filename";
|
||||||
|
node.filenameType = "msg";
|
||||||
$("#node-input-filename").typedInput("type", node.filenameType);
|
$("#node-input-filename").typedInput("type", node.filenameType);
|
||||||
$("#node-input-filename").typedInput("value", node.filename);
|
$("#node-input-filename").typedInput("value", node.filename);
|
||||||
|
} else if(/^\${[^}]+}$/.test(node.filename)) { //was using an ${ENV_VAR}
|
||||||
|
node.filenameType = "env";
|
||||||
|
node.filename = node.filename.replace(/\${([^}]+)}/g, function(match, name) {
|
||||||
|
return (name === undefined)?"":name;
|
||||||
|
});
|
||||||
|
$("#node-input-filename").typedInput("type", node.filenameType);
|
||||||
|
$("#node-input-filename").typedInput("value", node.filename);
|
||||||
|
} else { //was using a static filename - set typedInput type to str
|
||||||
|
node.filenameType = "str";
|
||||||
|
$("#node-input-filename").typedInput("type", node.filenameType);
|
||||||
|
$("#node-input-filename").typedInput("value", node.filename);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
encodings.forEach(function(item) {
|
encodings.forEach(function(item) {
|
||||||
if(Array.isArray(item)) {
|
if(Array.isArray(item)) {
|
||||||
@ -309,7 +324,8 @@
|
|||||||
icon: "file-in.svg",
|
icon: "file-in.svg",
|
||||||
label: function() {
|
label: function() {
|
||||||
var fn = this.filename;
|
var fn = this.filename;
|
||||||
if(this.filenameType != "str") { fn = ""; }
|
if(this.filenameType != "str" && this.filenameType != "env" ) { fn = ""; }
|
||||||
|
if(this.filenameType === "env") { fn = "env."+fn; }
|
||||||
return this.name||fn||this._("file.label.read");
|
return this.name||fn||this._("file.label.read");
|
||||||
},
|
},
|
||||||
paletteLabel: RED._("node-red:file.label.read"),
|
paletteLabel: RED._("node-red:file.label.read"),
|
||||||
@ -329,11 +345,25 @@
|
|||||||
types:[{ value: "str", label:"", icon:"red/images/typedInput/az.svg"}, "msg", "jsonata", "env"],
|
types:[{ value: "str", label:"", icon:"red/images/typedInput/az.svg"}, "msg", "jsonata", "env"],
|
||||||
typeField: $("#node-input-filenameType")
|
typeField: $("#node-input-filenameType")
|
||||||
});
|
});
|
||||||
if(!node.filename && !node.filenameType) {
|
if(typeof node.filenameType == 'undefined') {
|
||||||
node.filename = "filename"
|
//existing node AND filenameType is not set - inplace (compatible) upgrade to new typedInput
|
||||||
node.filenameType = "msg"
|
if(node.filename == "") { //was using empty value to denote msg.filename - set typedInput to match
|
||||||
|
node.filename = "filename";
|
||||||
|
node.filenameType = "msg";
|
||||||
$("#node-input-filename").typedInput("type", node.filenameType);
|
$("#node-input-filename").typedInput("type", node.filenameType);
|
||||||
$("#node-input-filename").typedInput("value", node.filename);
|
$("#node-input-filename").typedInput("value", node.filename);
|
||||||
|
} else if(/^\${[^}]+}$/.test(node.filename)) { //was using an ${ENV_VAR}
|
||||||
|
node.filenameType = "env";
|
||||||
|
node.filename = node.filename.replace(/\${([^}]+)}/g, function(match, name) {
|
||||||
|
return (name === undefined)?"":name;
|
||||||
|
});
|
||||||
|
$("#node-input-filename").typedInput("type", node.filenameType);
|
||||||
|
$("#node-input-filename").typedInput("value", node.filename);
|
||||||
|
} else { //was using a static filename - set typedInput type to str
|
||||||
|
node.filenameType = "str";
|
||||||
|
$("#node-input-filename").typedInput("type", node.filenameType);
|
||||||
|
$("#node-input-filename").typedInput("value", node.filename);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
encodings.forEach(function(item) {
|
encodings.forEach(function(item) {
|
||||||
if(Array.isArray(item)) {
|
if(Array.isArray(item)) {
|
||||||
|
@ -52,10 +52,20 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
function processMsg(msg,nodeSend, done) {
|
function processMsg(msg,nodeSend, done) {
|
||||||
var filename = node.filename || "";
|
var filename = node.filename || "";
|
||||||
//Pre V3 compatibility - if filename and filenameType are empty, check msg.filename
|
//Pre V3 compatibility - if filenameType is empty, do in place upgrade
|
||||||
if(!node.filenameType && !node.filename) {
|
if(typeof node.filenameType == 'undefined' || node.filenameType == "") {
|
||||||
msg.filename = "filename";
|
//existing node AND filenameType is not set - inplace (compatible) upgrade
|
||||||
|
if(filename == "") { //was using empty value to denote msg.filename
|
||||||
|
node.filename = "filename";
|
||||||
node.filenameType = "msg";
|
node.filenameType = "msg";
|
||||||
|
} else if(/^\${[^}]+}$/.test(filename)) { //was using an ${ENV_VAR}
|
||||||
|
node.filenameType = "env";
|
||||||
|
node.filename = filename.replace(/\${([^}]+)}/g, function(match, name) {
|
||||||
|
return (name === undefined)?"":name;
|
||||||
|
});
|
||||||
|
} else { //was using a static filename - set typedInput type to str
|
||||||
|
node.filenameType = "str";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RED.util.evaluateNodeProperty(node.filename,node.filenameType,node,msg,(err,value) => {
|
RED.util.evaluateNodeProperty(node.filename,node.filenameType,node,msg,(err,value) => {
|
||||||
@ -174,7 +184,7 @@ module.exports = function(RED) {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (node.filenameType === "str") {
|
if (node.filenameType === "str" || node.filenameType === "env") {
|
||||||
// Static filename - write and reuse the stream next time
|
// Static filename - write and reuse the stream next time
|
||||||
node.wstream.write(buf, function() {
|
node.wstream.write(buf, function() {
|
||||||
nodeSend(msg);
|
nodeSend(msg);
|
||||||
@ -288,12 +298,21 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
this.on("input",function(msg, nodeSend, nodeDone) {
|
this.on("input",function(msg, nodeSend, nodeDone) {
|
||||||
var filename = node.filename || "";
|
var filename = node.filename || "";
|
||||||
//Pre V3 compatibility - if filename and filenameType are empty, check msg.filename
|
//Pre V3 compatibility - if filenameType is empty, do in place upgrade
|
||||||
if(!node.filenameType && !node.filename) {
|
if(typeof node.filenameType == 'undefined' || node.filenameType == "") {
|
||||||
msg.filename = "filename";
|
//existing node AND filenameType is not set - inplace (compatible) upgrade
|
||||||
|
if(filename == "") { //was using empty value to denote msg.filename
|
||||||
|
node.filename = "filename";
|
||||||
node.filenameType = "msg";
|
node.filenameType = "msg";
|
||||||
|
} else if(/^\${[^}]+}$/.test(filename)) { //was using an ${ENV_VAR}
|
||||||
|
node.filenameType = "env";
|
||||||
|
node.filename = filename.replace(/\${([^}]+)}/g, function(match, name) {
|
||||||
|
return (name === undefined)?"":name;
|
||||||
|
});
|
||||||
|
} else { //was using a static filename - set typedInput type to str
|
||||||
|
node.filenameType = "str";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RED.util.evaluateNodeProperty(node.filename,node.filenameType,node,msg,(err,value) => {
|
RED.util.evaluateNodeProperty(node.filename,node.filenameType,node,msg,(err,value) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
node.error(err,msg);
|
node.error(err,msg);
|
||||||
|
@ -19,8 +19,6 @@
|
|||||||
Alternatively, it can delete the file.</p>
|
Alternatively, it can delete the file.</p>
|
||||||
<h3>Inputs</h3>
|
<h3>Inputs</h3>
|
||||||
<dl class="message-properties">
|
<dl class="message-properties">
|
||||||
<dt class="optional">filename <span class="property-type">string</span></dt>
|
|
||||||
<dd>If not configured in the node, this optional property sets the name of the file to be updated.</dd>
|
|
||||||
<dt class="optional">encoding <span class="property-type">string</span></dt>
|
<dt class="optional">encoding <span class="property-type">string</span></dt>
|
||||||
<dd>If encoding is configured to be set by msg, then this optional property can set the encoding.</dt>
|
<dd>If encoding is configured to be set by msg, then this optional property can set the encoding.</dt>
|
||||||
</dl>
|
</dl>
|
||||||
@ -40,11 +38,6 @@
|
|||||||
|
|
||||||
<script type="text/html" data-help-name="file in">
|
<script type="text/html" data-help-name="file in">
|
||||||
<p>Reads the contents of a file as either a string or binary buffer.</p>
|
<p>Reads the contents of a file as either a string or binary buffer.</p>
|
||||||
<h3>Inputs</h3>
|
|
||||||
<dl class="message-properties">
|
|
||||||
<dt class="optional">filename <span class="property-type">string</span></dt>
|
|
||||||
<dd>if not set in the node configuration, this property sets the filename to read.</dd>
|
|
||||||
</dl>
|
|
||||||
<h3>Outputs</h3>
|
<h3>Outputs</h3>
|
||||||
<dl class="message-properties">
|
<dl class="message-properties">
|
||||||
<dt>payload <span class="property-type">string | buffer</span></dt>
|
<dt>payload <span class="property-type">string | buffer</span></dt>
|
||||||
|
Loading…
Reference in New Issue
Block a user