UNPKG

node-red-contrib-multipart-stream-decoder

Version:
183 lines (178 loc) 9.3 kB
<!-- Copyright 2017, Bart Butenaers Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <script type="text/x-red" data-template-name="multipart-decoder"> <div class="form-row"> <label for="node-input-name"><i class="fa fa-tag"></i> Name</label> <input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name"> </div> </br> <div class="form-row"> <label for="node-input-url"><i class="fa fa-globe"></i> URL</label> <input id="node-input-url" type="text" placeholder="http://"> </div> <div class="form-row"> <input type="checkbox" id="node-input-usetls" style="display: inline-block; width: auto; vertical-align: top;"> <label for="node-input-usetls" style="width: auto">Enable secure (SSL/TLS) connection</label> <div id="node-row-tls" class="hide"> <label style="width: auto; margin-left: 20px; margin-right: 10px;" for="node-input-tls">TLS Configuration</label><input type="text" style="width: 300px" id="node-input-tls"> </div> </div> <div class="form-row"> <label for="node-input-authentication"><i class="fa fa-id-card-o"></i> Authenticate</label> <select type="text" id="node-input-authentication" style="width:70%;"> <option value="none"> None</option> <option value="basic"> Basic</option> <option value="digest"> Digest</option> </select> </div> <div class="form-row authentication-row"> <label for="node-input-user"><i class="fa fa-user"></i> Username</label> <input type="text" id="node-input-user"> </div> <div class="form-row authentication-row"> <label for="node-input-password"><i class="fa fa-lock"></i> Password</label> <input type="password" id="node-input-password"> </div> <div class="form-row"> <label for="node-input-ret"><i class="fa fa-arrow-left"></i> Output</label> <select type="text" id="node-input-ret" style="width:70%;"> <option value="txt"> a UTF-8 string</option> <option value="bin"> a binary buffer</option> <option value="obj"> a parsed JSON object</option> </select> </div> <div class="form-row"> <label for="node-input-delay"><i class="fa fa-clock-o"></i> Delay</label> <input type="text" id="node-input-delay"> </div> <div class="form-row"> <label for="node-input-blockSize"><i class="fa fa-arrows-alt-h"></i> Block size</label> <input type="text" id="node-input-blockSize"> </div> <div class="form-row"> <label for="node-input-maximum"><i class="fa fa-hashtag"></i> Max. size</label> <input type="text" id="node-input-maximum"> </div> <div class="form-row"> <label for="node-input-enableLog"><i class="fa fa-eye"></i> Debug log</label> <select type="text" id="node-input-enableLog" style="width:70%;"> <option value="on"> On</option> <option value="off"> Off</option> </select> </div> </script> <script type="text/x-red" data-help-name="multipart-decoder"> <p>A Node-RED node for decoding multipart http streams.</p> <p><strong>URL:</strong><br/> The http(s) url (to a multipart resource) is required except when it is specified in the input message via <code>msg.url</code>.<br/> That msg.url property can contain <a href="http://mustache.github.io/mustache.5.html" target="_blank">mustache-style</a> tags. These allow the url to be constructed using values of the incoming message. For example, if the url is set to <code>example.com/{{{topic}}}</code>, it will have the value of <code>msg.topic</code> automatically inserted. Using {{{...}}} prevents mustache from escaping characters like / & etc.</p> <p><strong>Authenticate:</strong><br/> <p>Specify whether the url requires (basic or digest) authentication, and enter the credentials.</p> <p><strong>Delay:</strong><br/> The (minimum) number of milliseconds between parts in a multipart stream, to allow throttling the stream.</p> <p><strong>Block size:</strong><br/> The number of parts in the output <code>msg.payload</code>. E.g. when set to value 3, the output <code>msg.payload</code> will contain an array of 3 parts. When set to value 1, the output <code>msg.payload</code> will contain only 1 part (not an array containing 1 part!).</p> <p>If you need to configure a proxy please add <b>http_proxy=...</b> to your environment variables and restart Node-RED.</p> <p><strong>Max. size:</strong><br/> The maximum total size of all messages that will be buffered. When no boundary separator is found within these chunks, then the stream will automatically be aborted.</p> <p><strong>Debug log:</strong><br/> When enabled, some extra logs will appear in the console log, which can be used for troubleshooting.</p> <p>The <strong>output message</strong> contains the following properties: <ul> <li><code>payload</code> is the body of the response</li> <li><code>statusCode</code> is the status code of the response, or the error code if the request could not be completed</li> <li><code>responseUrl</code> is the url of the server that responds</li> <li><code>content</code> contains the http headers of the current part</li> </ul></p> <p>The <strong>input message</strong> can contain the following properties (apart from optional properties used for mustache expressions): <ul> <li><code>url</code> is required when the URL is not specified in the node. Otherwise it will be ignored.</li> <li><code>stop</code> will stop the current stream if set to 'true' (which can be used if no new stream has to be started).</li> <li><code>delay</code> will be used to throttle the stream, if no delay has been specified in the node.</li> </ul></p> </script> <script type="text/javascript"> RED.nodes.registerType('multipart-decoder',{ category: 'function', color:"rgb(231, 231, 174)", defaults: { name: {value:""}, ret: {value:"txt"}, url:{value:""}, tls: {type:"tls-config",required: false}, authentication: {value: "basic"}, delay: {value:0, required: false, validate:function(value) { return !value || !isNaN(value); }}, maximum: {value:1000000, required: true, validate:function(value) { return !value || !isNaN(value); }}, blockSize: {value:1, required: false, validate:function(value) { return !value || !isNaN(value) || value<1; }}, enableLog: {value: "off"} }, credentials: { user: {type:"text"}, password: {type: "password"} }, inputs:1, outputs:2, outputLabels: ["data/parts", "errors"], icon: "decoder.png", label: function() { return this.name || "multipart decoder"; }, labelStyle: function() { return this.name?"node_label_italic":""; }, oneditprepare: function() { // Set default values for some properties that old nodes don't have these properties yet. $('#node-input-blockSize').val(this.blockSize || 1); $('#node-input-authentication').val(this.authentication || ((this.useAuth) ? "basic" : "none")); $('#node-input-enableLog').val(this.enableLog || "off"); $("#node-input-authentication").change(function() { if (this.value == "none") { $(".authentication-row").hide(); } else { $(".authentication-row").show(); } }); function updateTLSOptions() { if ($("#node-input-usetls").is(':checked')) { $("#node-row-tls").show(); } else { $("#node-row-tls").hide(); } } if (this.tls) { $('#node-input-usetls').prop('checked', true); } else { $('#node-input-usetls').prop('checked', false); } updateTLSOptions(); $("#node-input-usetls").on("click",function() { updateTLSOptions(); }); $("#node-input-ret").change(function() { if ($("#node-input-ret").val() === "obj") { $("#tip-json").show(); } else { $("#tip-json").hide(); } }); }, oneditsave: function() { if (!$("#node-input-usetls").is(':checked')) { $("#node-input-tls").val("_ADD_"); } } }); </script>