mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Make new Auto Output mode optional
- adds entry to output data type - adds depreciation tip
This commit is contained in:
parent
dbdd1b8671
commit
552408f488
@ -65,6 +65,11 @@
|
|||||||
/* opacity: 0.3;
|
/* opacity: 0.3;
|
||||||
pointer-events: none; */
|
pointer-events: none; */
|
||||||
}
|
}
|
||||||
|
.form-row.form-row-mqtt-datatype-tip > .form-tips {
|
||||||
|
width: calc(70% - 18px);
|
||||||
|
display: inline-block;
|
||||||
|
margin-top: -8px;
|
||||||
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
@ -121,6 +126,7 @@
|
|||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-datatype"><i class="fa fa-sign-out"></i> <span data-i18n="mqtt.label.output"></span></label>
|
<label for="node-input-datatype"><i class="fa fa-sign-out"></i> <span data-i18n="mqtt.label.output"></span></label>
|
||||||
<select id="node-input-datatype" style="width:70%;">
|
<select id="node-input-datatype" style="width:70%;">
|
||||||
|
<option value="auto-detect" data-i18n="mqtt.output.auto-detect"></option>
|
||||||
<option value="auto" data-i18n="mqtt.output.auto"></option>
|
<option value="auto" data-i18n="mqtt.output.auto"></option>
|
||||||
<option value="buffer" data-i18n="mqtt.output.buffer"></option>
|
<option value="buffer" data-i18n="mqtt.output.buffer"></option>
|
||||||
<option value="utf8" data-i18n="mqtt.output.string"></option>
|
<option value="utf8" data-i18n="mqtt.output.string"></option>
|
||||||
@ -128,6 +134,10 @@
|
|||||||
<option value="base64" data-i18n="mqtt.output.base64"></option>
|
<option value="base64" data-i18n="mqtt.output.base64"></option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-row form-row-mqtt-datatype-tip">
|
||||||
|
<label> </label>
|
||||||
|
<div class="form-tips" id="mqtt-in-datatype-depreciated-tip"><span data-i18n="mqtt.label.auto-mode-depreciated"></span></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-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">
|
||||||
@ -750,7 +760,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
qos: {value: "2"},
|
qos: {value: "2"},
|
||||||
datatype: {value:"auto",required:true},
|
datatype: {value:"auto-detect",required:true},
|
||||||
broker: {type:"mqtt-broker", required:true},
|
broker: {type:"mqtt-broker", required:true},
|
||||||
// subscriptionIdentifier: {value:0},
|
// subscriptionIdentifier: {value:0},
|
||||||
nl: {value:false},
|
nl: {value:false},
|
||||||
@ -787,6 +797,16 @@
|
|||||||
$("div.form-row-mqtt5").toggleClass("form-row-mqtt5-active",!!v5);
|
$("div.form-row-mqtt5").toggleClass("form-row-mqtt5-active",!!v5);
|
||||||
$("div.form-row.form-row-mqtt-static").toggleClass("form-row-mqtt-static-disabled", !!dynamic)
|
$("div.form-row.form-row-mqtt-static").toggleClass("form-row-mqtt-static-disabled", !!dynamic)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$("#node-input-datatype").on("change", function() {
|
||||||
|
if($(this).val() === "auto") {
|
||||||
|
$(".form-row.form-row-mqtt-datatype-tip").show();
|
||||||
|
} else {
|
||||||
|
$(".form-row.form-row-mqtt-datatype-tip").hide();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
$("#node-input-datatype").trigger("change");
|
||||||
|
|
||||||
$("#node-input-broker").on("change",function(d){
|
$("#node-input-broker").on("change",function(d){
|
||||||
updateVisibility();
|
updateVisibility();
|
||||||
});
|
});
|
||||||
@ -807,7 +827,7 @@
|
|||||||
$("#node-input-qos").val("2");
|
$("#node-input-qos").val("2");
|
||||||
}
|
}
|
||||||
if (this.datatype === undefined) {
|
if (this.datatype === undefined) {
|
||||||
$("#node-input-datatype").val("auto");
|
$("#node-input-datatype").val("auto-detect");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
oneditsave: function() {
|
oneditsave: function() {
|
||||||
|
@ -25,7 +25,7 @@ module.exports = function(RED) {
|
|||||||
"text/html":"string",
|
"text/html":"string",
|
||||||
"text/plain":"string",
|
"text/plain":"string",
|
||||||
"text/html":"string",
|
"text/html":"string",
|
||||||
"application/json":"object",
|
"application/json":"json",
|
||||||
"application/octet-stream":"buffer",
|
"application/octet-stream":"buffer",
|
||||||
"application/pdf":"buffer",
|
"application/pdf":"buffer",
|
||||||
"application/x-gtar":"buffer",
|
"application/x-gtar":"buffer",
|
||||||
@ -235,14 +235,15 @@ module.exports = function(RED) {
|
|||||||
if (v5isUtf8 || isUtf8(payload)) {
|
if (v5isUtf8 || isUtf8(payload)) {
|
||||||
try {
|
try {
|
||||||
payload = JSON.parse(payload.toString());
|
payload = JSON.parse(payload.toString());
|
||||||
} catch(e) {
|
} catch (e) {
|
||||||
node.error(RED._("mqtt.errors.invalid-json-parse"),{payload:payload, topic:topic, qos:packet.qos, retain:packet.retain}); return;
|
node.error(RED._("mqtt.errors.invalid-json-parse"), { payload: payload, topic: topic, qos: packet.qos, retain: packet.retain }); return;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
node.error((RED._("mqtt.errors.invalid-json-string")), { payload: payload, topic: topic, qos: packet.qos, retain: packet.retain }); return;
|
||||||
}
|
}
|
||||||
else { node.error((RED._("mqtt.errors.invalid-json-string")),{payload:payload, topic:topic, qos:packet.qos, retain:packet.retain}); return; }
|
|
||||||
} else {
|
} else {
|
||||||
//auto
|
//"auto" (legacy) or "auto-detect" (new default)
|
||||||
if(v5isUtf8 || v5HasMediaType) {
|
if (v5isUtf8 || v5HasMediaType) {
|
||||||
const outputType = knownMediaTypes[v5MediaTypeLC]
|
const outputType = knownMediaTypes[v5MediaTypeLC]
|
||||||
switch (outputType) {
|
switch (outputType) {
|
||||||
case "string":
|
case "string":
|
||||||
@ -251,25 +252,39 @@ module.exports = function(RED) {
|
|||||||
case "buffer":
|
case "buffer":
|
||||||
//no change
|
//no change
|
||||||
break;
|
break;
|
||||||
case "object":
|
case "json":
|
||||||
try {
|
try {
|
||||||
payload = JSON.parse(payload.toString());
|
//since v5 type states this should be JSON, parse it & error out if NOT JSON
|
||||||
} catch(e) {
|
payload = payload.toString()
|
||||||
node.error(RED._("mqtt.errors.invalid-json-parse"),{payload:payload, topic:topic, qos:packet.qos, retain:packet.retain}); return;
|
const obj = JSON.parse(payload);
|
||||||
|
if (datatype === "auto-detect") {
|
||||||
|
payload = obj; //as mode is "auto-detect", return the parsed JSON
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
node.error(RED._("mqtt.errors.invalid-json-parse"), { payload: payload, topic: topic, qos: packet.qos, retain: packet.retain }); return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (v5isUtf8 || isUtf8(payload)) {
|
if (v5isUtf8 || isUtf8(payload)) {
|
||||||
payload = payload.toString(); //auto String
|
payload = payload.toString(); //auto String
|
||||||
|
if (datatype === "auto-detect") {
|
||||||
|
try {
|
||||||
|
payload = JSON.parse(payload); //auto to parsed object (attempt)
|
||||||
|
} catch (e) {
|
||||||
|
/* mute error - it simply isnt JSON, just leave payload as a string */
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (isUtf8(payload)) {
|
} else if (isUtf8(payload)) {
|
||||||
payload = payload.toString(); //auto String
|
payload = payload.toString(); //auto String
|
||||||
try {
|
if (datatype === "auto-detect") {
|
||||||
payload = JSON.parse(payload);
|
try {
|
||||||
} catch(e) {
|
payload = JSON.parse(payload);
|
||||||
/* mute error - it simply isnt JSON, just leave payload as a string */
|
} catch (e) {
|
||||||
|
/* mute error - it simply isnt JSON, just leave payload as a string */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} //else {
|
} //else {
|
||||||
//leave as buffer
|
//leave as buffer
|
||||||
|
@ -422,7 +422,8 @@
|
|||||||
"buffer": "Einen binären Buffer",
|
"buffer": "Einen binären Buffer",
|
||||||
"string": "Ein String",
|
"string": "Ein String",
|
||||||
"base64": "Ein Base64-kodierter String",
|
"base64": "Ein Base64-kodierter String",
|
||||||
"auto": "Auto-Erkennung (parsed JSON-Objekt, string oder buffer)",
|
"auto": "Auto-Erkennung (string oder buffer)",
|
||||||
|
"auto-detect": "Auto-Erkennung (parsed JSON-Objekt, string oder buffer)",
|
||||||
"json": "Ein analysiertes (parsed) JSON-Objekt"
|
"json": "Ein analysiertes (parsed) JSON-Objekt"
|
||||||
},
|
},
|
||||||
"true": "wahr",
|
"true": "wahr",
|
||||||
|
@ -424,7 +424,8 @@
|
|||||||
"action": "Action",
|
"action": "Action",
|
||||||
"staticTopic": "Subscribe to single topic",
|
"staticTopic": "Subscribe to single topic",
|
||||||
"dynamicTopic": "Dynamic subscription",
|
"dynamicTopic": "Dynamic subscription",
|
||||||
"auto-connect": "Connect automatically"
|
"auto-connect": "Connect automatically",
|
||||||
|
"auto-mode-depreciated": "This option is depreciated. Please use the new auto-detect mode."
|
||||||
},
|
},
|
||||||
"sections-label":{
|
"sections-label":{
|
||||||
"birth-message": "Message sent on connection (birth message)",
|
"birth-message": "Message sent on connection (birth message)",
|
||||||
@ -454,7 +455,8 @@
|
|||||||
"buffer": "a Buffer",
|
"buffer": "a Buffer",
|
||||||
"string": "a String",
|
"string": "a String",
|
||||||
"base64": "a Base64 encoded string",
|
"base64": "a Base64 encoded string",
|
||||||
"auto": "auto-detect (parsed JSON object, string or buffer)",
|
"auto": "auto-detect (string or buffer)",
|
||||||
|
"auto-detect": "auto-detect (parsed JSON object, string or buffer)",
|
||||||
"json": "a parsed JSON object"
|
"json": "a parsed JSON object"
|
||||||
},
|
},
|
||||||
"true": "true",
|
"true": "true",
|
||||||
|
@ -454,7 +454,8 @@
|
|||||||
"buffer": "バイナリバッファ",
|
"buffer": "バイナリバッファ",
|
||||||
"string": "文字列",
|
"string": "文字列",
|
||||||
"base64": "Base64文字列",
|
"base64": "Base64文字列",
|
||||||
"auto": "自動判定(JSONオブジェクト、文字列もしくはバイナリバッファ)",
|
"auto": "自動判定(文字列もしくはバイナリバッファ)",
|
||||||
|
"auto-detect": "自動判定(JSONオブジェクト、文字列もしくはバイナリバッファ)",
|
||||||
"json": "JSONオブジェクト"
|
"json": "JSONオブジェクト"
|
||||||
},
|
},
|
||||||
"true": "する",
|
"true": "する",
|
||||||
|
@ -361,7 +361,8 @@
|
|||||||
"buffer": "바이너리 버퍼",
|
"buffer": "바이너리 버퍼",
|
||||||
"string": "문자열",
|
"string": "문자열",
|
||||||
"base64": "Base64문자열",
|
"base64": "Base64문자열",
|
||||||
"auto": "자동판정(JSON오브젝트, 문자열혹은 바이너리버퍼)",
|
"auto": "자동판정(문자열혹은 바이너리버퍼)",
|
||||||
|
"auto-detect": "자동판정(JSON오브젝트, 문자열혹은 바이너리버퍼)",
|
||||||
"json": "JSON오브젝트"
|
"json": "JSON오브젝트"
|
||||||
},
|
},
|
||||||
"true": "한다",
|
"true": "한다",
|
||||||
|
@ -384,7 +384,8 @@
|
|||||||
"buffer": "буфер",
|
"buffer": "буфер",
|
||||||
"string": "строка",
|
"string": "строка",
|
||||||
"base64": "строка в кодировке Base64",
|
"base64": "строка в кодировке Base64",
|
||||||
"auto": "автоопределение (разобрать объект JSON, строка или буфер)",
|
"auto": "автоопределение (строка или буфер)",
|
||||||
|
"auto-detect": "автоопределение (разобрать объект JSON, строка или буфер)",
|
||||||
"json": "объект JSON"
|
"json": "объект JSON"
|
||||||
},
|
},
|
||||||
"true": "да",
|
"true": "да",
|
||||||
|
@ -381,7 +381,8 @@
|
|||||||
"buffer": "Buffer",
|
"buffer": "Buffer",
|
||||||
"string": "字符串",
|
"string": "字符串",
|
||||||
"base64": "Base64编码字符串",
|
"base64": "Base64编码字符串",
|
||||||
"auto": "自动检测 (已解析的JSON对象、字符串或buffer)",
|
"auto": "自动检测 (字符串或buffer)",
|
||||||
|
"auto-detect": "自动检测 (已解析的JSON对象、字符串或buffer)",
|
||||||
"json": "解析的JSON对象"
|
"json": "解析的JSON对象"
|
||||||
},
|
},
|
||||||
"true": "是",
|
"true": "是",
|
||||||
|
@ -385,7 +385,8 @@
|
|||||||
"buffer": "Buffer",
|
"buffer": "Buffer",
|
||||||
"string": "字串",
|
"string": "字串",
|
||||||
"base64": "Base64編碼字串",
|
"base64": "Base64編碼字串",
|
||||||
"auto": "自动检测 (已解析的JSON对象、字符串或buffer)",
|
"auto": "自動檢測 (字符串或buffer)",
|
||||||
|
"auto-detect": "自动检测 (已解析的JSON对象、字符串或buffer)",
|
||||||
"json": "解析的JSON對象"
|
"json": "解析的JSON對象"
|
||||||
},
|
},
|
||||||
"true": "是",
|
"true": "是",
|
||||||
|
Loading…
Reference in New Issue
Block a user