Dia antes primera install
This commit is contained in:
201
node_modules/node-red-contrib-ui-upload/LICENSE.md
generated
vendored
Normal file
201
node_modules/node-red-contrib-ui-upload/LICENSE.md
generated
vendored
Normal file
@@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
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.
|
||||
54
node_modules/node-red-contrib-ui-upload/README.md
generated
vendored
Normal file
54
node_modules/node-red-contrib-ui-upload/README.md
generated
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
# node-red-contrib-ui-upload
|
||||
|
||||
[Node-RED Dashboard](https://github.com/node-red/node-red-dashboard) UI widget node for **uploading** a file content by WebSocket (Socket.io) streaming.
|
||||
|
||||
Supports: browse for file or drag & drop; pause & resume, replay; custom chunk size; backpressure.
|
||||
|
||||
Meant to be combined with [node-red-contrib-chunks-to-lines](https://github.com/alexandrainst/node-red-contrib-chunks-to-lines).
|
||||
|
||||
Screenshot in the Node-RED Dashboard:
|
||||
|
||||

|
||||
|
||||
In a Node-RED flow, this *Upload node* (using *text* transfer type) can advantageously be connected to some standard nodes such as:
|
||||
|
||||
* *Split node* using the option *Handle as a stream of messages*: to read one line at a time (works well, also for very large uploaded files)
|
||||
* *Join node* using the *automatic* mode: to reassemble the uploaded chunks into one single message / string (only for relatively small uploaded files, which can fit in memory)
|
||||
|
||||
Example: [flow.json](examples/flow.json)
|
||||
|
||||

|
||||
|
||||
But this node really shines when combined with the [node-red-contrib-chunks-to-lines](https://github.com/alexandrainst/node-red-contrib-chunks-to-lines) node, which can split in a more efficient way, e.g. safe for Unicode and with built-in backpressure for automatic buffering optimisation.
|
||||
|
||||
Example: [flow.json](https://github.com/alexandrainst/node-red-contrib-chunks-to-lines/blob/main/examples/flow.json)
|
||||
|
||||

|
||||
|
||||
See also a more advanced [example of upload of a large CSV file to an SQL database](https://flows.nodered.org/flow/687918dd5cb66a3bfc2a661e15ef4237).
|
||||
|
||||
## Transfer types
|
||||
|
||||
* When using *binary* transfer type, the data is uploaded as chunks of byte arrays. This mode can safely transmit any type of file, but requires a transformation before further use (which [node-red-contrib-chunks-to-lines](https://github.com/alexandrainst/node-red-contrib-chunks-to-lines) can handle).
|
||||
* When using *text* transfer type, the data is uploaded as chunks of ASCII (more precisely Windows-1252 encoding). This mode is **not able** to properly transmit non-ASCII data such as multibyte strings (e.g. Unicode / UTF-8) or binary files, but is convenient for basic ASCII text.
|
||||
|
||||
## Backpressure
|
||||
|
||||
This node supports *backpressure* / *flow control*:
|
||||
it can wait for a *tick* before uploading the next chunk of data,
|
||||
to make sure the rest of your Node-RED flow is ready to process more data, instead of risking an out-of-memory condition.
|
||||
|
||||
To make this behaviour potentially automatic (avoiding manual wires), this node declares its ability by exposing a truthy `node.tickConsumer` for downstream nodes to detect this feature.
|
||||
Using this approach, the backpressure is done automatically when using the [node-red-contrib-chunks-to-lines](https://github.com/alexandrainst/node-red-contrib-chunks-to-lines) node.
|
||||
|
||||
For a manual approach, just send `{ tick: true }` to the node for triggering the upload of the next chunk of data.
|
||||
|
||||
By default, in absence of wired input on this node, a tick will be automatically generated upon full reception of a chunk of data to trigger the upload of the next one.
|
||||
|
||||
This backpressure mechanism also gives time to other nodes communicating on the same shared WebSocket and avoids disconnections when uploading large files.
|
||||
|
||||
## Credits
|
||||
|
||||
License: [Apache 2.0](LICENSE.md), 2020-2022.
|
||||
|
||||
Originally made by [Alexandre Alapetite](https://alexandra.dk/alexandre.alapetite) at the [Alexandra Institute](https://alexandra.dk).
|
||||
55
node_modules/node-red-contrib-ui-upload/package.json
generated
vendored
Normal file
55
node_modules/node-red-contrib-ui-upload/package.json
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
{
|
||||
"name": "node-red-contrib-ui-upload",
|
||||
"version": "0.8.1",
|
||||
"description": "Node-RED Dashboard UI widget node for uploading a file content by Socket.io streaming",
|
||||
"keywords": [
|
||||
"upload",
|
||||
"backpressure",
|
||||
"websocket",
|
||||
"ui",
|
||||
"dashboard",
|
||||
"node-red",
|
||||
"node-red-contrib",
|
||||
"node-red-ui",
|
||||
"nodered"
|
||||
],
|
||||
"author": {
|
||||
"name": "Alexandre Alapetite",
|
||||
"url": "https://alexandra.dk/alexandre.alapetite"
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"main": "ui_upload.js",
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
},
|
||||
"node-red": {
|
||||
"version": ">=0.20.0",
|
||||
"nodes": {
|
||||
"ui_upload": "ui_upload.js"
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"ui_upload.html",
|
||||
"ui_upload.js"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/alexandrainst/node-red-contrib-ui-upload"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^8.51.0",
|
||||
"eslint-config-standard": "^17.1.0",
|
||||
"eslint-plugin-html": "^7.1.0",
|
||||
"eslint-plugin-import": "^2.28.1",
|
||||
"eslint-plugin-n": "^16.2.0",
|
||||
"eslint-plugin-promise": "^6.1.1"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "node ./index.js",
|
||||
"eslint": "eslint --ext .js,.html .",
|
||||
"eslint_fix": "eslint --fix --ext .js,.html .",
|
||||
"fix": "npm run eslint_fix",
|
||||
"pretest": "npm run-script eslint",
|
||||
"test": "npm -v"
|
||||
}
|
||||
}
|
||||
87
node_modules/node-red-contrib-ui-upload/ui_upload.html
generated
vendored
Normal file
87
node_modules/node-red-contrib-ui-upload/ui_upload.html
generated
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
<script type="text/x-red" data-template-name="ui_upload">
|
||||
<div class="form-row" id="template-row-group">
|
||||
<label for="node-input-group"><i class="fa fa-table"></i> Group</label>
|
||||
<input type="text" id="node-input-group" />
|
||||
</div>
|
||||
<div class="form-row" id="template-row-size">
|
||||
<label><i class="fa fa-object-group"></i> Size</label>
|
||||
<input type="hidden" id="node-input-width" />
|
||||
<input type="hidden" id="node-input-height" />
|
||||
<button class="editor-button" id="node-input-size"></button>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-title"><i class="fa fa-i-cursor"></i> Title</label>
|
||||
<input type="text" id="node-input-title" />
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
||||
<input type="text" id="node-input-name" />
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-accept"><i class="fa fa-filter"></i> Accept file types</label>
|
||||
<input type="text" id="node-input-accept" placeholder="text/*,.csv,.txt" />
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-chunk"><i class="fa fa-sign-in"></i> Chunk size (kB)</label>
|
||||
<input type="number" id="node-input-chunk" min="1" max="2048" />
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-transfer"><i class="fa fa-flag"></i> Transfer type</label>
|
||||
<select id="node-input-transfer">
|
||||
<option value="text">Text (Windows-1252 / ASCII / ANSI)</option>
|
||||
<option value="binary">Binary</option>
|
||||
</select>
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="ui_upload">
|
||||
<p>UI widget node for uploading files content by Socket.io streaming</p>
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
/* global RED:false, $:false */
|
||||
|
||||
function uiUploadConf(NAME) {
|
||||
const ICON = 'white-globe.svg';
|
||||
|
||||
return {
|
||||
category: 'dashboard',
|
||||
color: 'rgb(63, 173, 181)',
|
||||
defaults: {
|
||||
group: { type: 'ui_group', required: true },
|
||||
title: { value: 'upload' },
|
||||
accept: { value: '' },
|
||||
name: { value: '' },
|
||||
order: { value: 0 },
|
||||
width: {
|
||||
value: 0,
|
||||
validate: function (v) {
|
||||
const width = +v || 0;
|
||||
const currentGroup = $('#node-input-group').val() || this.group;
|
||||
const groupNode = RED.nodes.node(currentGroup);
|
||||
const valid = !groupNode || +width <= +groupNode.width;
|
||||
$('#node-input-size').toggleClass('input-error', !valid);
|
||||
return valid;
|
||||
},
|
||||
},
|
||||
height: { value: 5 },
|
||||
chunk: { value: 256 },
|
||||
transfer: { value: 'binary' },
|
||||
},
|
||||
inputs: 1,
|
||||
outputs: 1,
|
||||
icon: ICON,
|
||||
paletteLabel: NAME,
|
||||
label: function () { return this.name || NAME; },
|
||||
oneditprepare: function () {
|
||||
$('#node-input-size').elementSizer({
|
||||
width: '#node-input-width',
|
||||
height: '#node-input-height',
|
||||
group: '#node-input-group',
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
RED.nodes.registerType('ui_upload', uiUploadConf('upload'));
|
||||
</script>
|
||||
344
node_modules/node-red-contrib-ui-upload/ui_upload.js
generated
vendored
Normal file
344
node_modules/node-red-contrib-ui-upload/ui_upload.js
generated
vendored
Normal file
@@ -0,0 +1,344 @@
|
||||
'use strict';
|
||||
|
||||
function html(config) {
|
||||
const jsonConfig = JSON.stringify(config);
|
||||
return String.raw`
|
||||
<style>
|
||||
.ui_upload {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
justify-content: space-evenly;
|
||||
}
|
||||
.ui_upload p.title {
|
||||
background: transparent !important;
|
||||
font-size: 175%;
|
||||
text-align: center;
|
||||
width: 99%;
|
||||
}
|
||||
.ui_upload > progress {
|
||||
width: 90%;
|
||||
}
|
||||
.ui_upload.done > progress {
|
||||
display: none;
|
||||
}
|
||||
.ui_upload > p.result {
|
||||
font-size: 150%;
|
||||
}
|
||||
.ui_upload:not(.done) > p.result {
|
||||
display: none;
|
||||
}
|
||||
.ui_upload > button {
|
||||
background: transparent;
|
||||
border: 0;
|
||||
font-size: xx-large;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
.ui_upload > button[disabled] {
|
||||
filter: grayscale(1) brightness(1.5);
|
||||
}
|
||||
</style>
|
||||
|
||||
<div id="ui_upload-{{unique}}" class="ui_upload"
|
||||
ng-init='init(` + jsonConfig + `)'
|
||||
style="width:{{width}}"
|
||||
ng-on-dragleave="ondragleave($event)" ng-on-dragenter="ondragenter($event)"
|
||||
ng-on-dragover="ondragover($event)" ng-on-drop="ondrop($event)">
|
||||
<p class="title">{{title}}</p>
|
||||
<progress value="0" max="100"></progress>
|
||||
<p class="result">✔️ <small>0s</small></p>
|
||||
<input type="file" ng-on-change="onchange($event)" name="ui_upload-filename" accept="{{accept}}" />
|
||||
<button class="play" ng-click="playClick($event)" disabled="disabled">▶️</button>
|
||||
<button class="stop" ng-click="stopClick($event)" disabled="disabled">⏹️</button>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
// NB: This function goes through a toString + eval by Node-RED Dashboard, so no scope
|
||||
function initController($scope, events) {
|
||||
$scope.init = function (config) {
|
||||
$scope.config = config;
|
||||
$scope.unique = $scope.$eval('$id');
|
||||
$scope.title = config.title || config.name || 'Upload';
|
||||
$scope.accept = '' + config.accept;
|
||||
$scope.chunkCallback = null;
|
||||
$scope.downstreamReady = false;
|
||||
// TODO: Find a cleaner approach for the width
|
||||
$scope.width = (Math.max(config.width || 12, 4) * 52.5) + 'px';
|
||||
};
|
||||
|
||||
$scope.$watch('msg', function (msg) {
|
||||
// Message received from back-end
|
||||
if (msg && msg.tick && !$scope.stop && !$scope.pause) {
|
||||
if ($scope.chunkCallback) {
|
||||
$scope.chunkCallback.f($scope.chunkCallback.e);
|
||||
} else {
|
||||
$scope.downstreamReady = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
function sendFile(file) {
|
||||
const div = document.getElementById('ui_upload-' + $scope.unique);
|
||||
div.classList.remove('done');
|
||||
const progress = div.querySelector('progress');
|
||||
$scope.stop = false;
|
||||
$scope.downstreamReady = true;
|
||||
|
||||
delete $scope.duration;
|
||||
const startTime = Date.now() - 1;
|
||||
const chunk = 1024 * Math.max($scope.config.chunk || 1024, 1);
|
||||
const count = Math.ceil(file.size / chunk);
|
||||
const partsId = file.name + ';' + file.size + ';' + Date.now();
|
||||
let partsIndex = -1;
|
||||
let loaded = 0;
|
||||
|
||||
let blob;
|
||||
const fileReader = new FileReader();
|
||||
fileReader.onload = function (e) {
|
||||
if ($scope.stop) {
|
||||
// Send special paquet to inform the rest of the pipeline
|
||||
$scope.send({
|
||||
file: {
|
||||
lastModified: file.lastModified,
|
||||
name: file.name,
|
||||
size: file.size,
|
||||
type: file.type,
|
||||
},
|
||||
parts: {
|
||||
id: partsId,
|
||||
type: 'string',
|
||||
ch: '',
|
||||
index: partsIndex + 1,
|
||||
count: partsIndex + 2,
|
||||
chunk: chunk,
|
||||
abort: true,
|
||||
},
|
||||
payload: '',
|
||||
});
|
||||
$scope.stopClick();
|
||||
return;
|
||||
} else if (!$scope.chunkCallback && ($scope.pause || !$scope.downstreamReady)) {
|
||||
$scope.chunkCallback = { f: fileReader.onload, e: e };
|
||||
return;
|
||||
}
|
||||
partsIndex++;
|
||||
$scope.chunkCallback = false;
|
||||
$scope.downstreamReady = false;
|
||||
$scope.send({
|
||||
file: {
|
||||
lastModified: file.lastModified,
|
||||
name: file.name,
|
||||
size: file.size,
|
||||
type: file.type,
|
||||
},
|
||||
parts: {
|
||||
id: partsId,
|
||||
type: 'string',
|
||||
ch: '',
|
||||
index: partsIndex,
|
||||
count: count,
|
||||
chunk: chunk,
|
||||
},
|
||||
payload: e.target.result,
|
||||
complete: partsIndex + 1 >= count ? true : undefined,
|
||||
});
|
||||
loaded += chunk;
|
||||
progress.value = 100 * loaded / file.size;
|
||||
if (loaded <= file.size) {
|
||||
blob = file.slice(loaded, loaded + chunk);
|
||||
if ($scope.config.transfer === 'text') {
|
||||
fileReader.readAsText(blob, 'Windows-1252');
|
||||
} else {
|
||||
fileReader.readAsArrayBuffer(blob);
|
||||
}
|
||||
} else {
|
||||
loaded = file.size;
|
||||
$scope.duration = Math.ceil((Date.now() - startTime) / 1000);
|
||||
$scope.stopClick();
|
||||
}
|
||||
};
|
||||
|
||||
blob = file.slice(0, chunk);
|
||||
if ($scope.config.transfer === 'text') {
|
||||
// NB: Can only be a single-byte encoding / ASCII, so no Unicode / UTF-8!
|
||||
fileReader.readAsText(blob, 'Windows-1252');
|
||||
} else {
|
||||
fileReader.readAsArrayBuffer(blob);
|
||||
}
|
||||
}
|
||||
|
||||
let backgroundColor = '';
|
||||
|
||||
$scope.ondragleave = function (e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
const div = e.currentTarget;
|
||||
div.style.background = backgroundColor;
|
||||
};
|
||||
|
||||
$scope.ondragenter = function (e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
};
|
||||
|
||||
$scope.ondragover = function (e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
const div = e.currentTarget;
|
||||
backgroundColor |= div.style.background;
|
||||
div.style.background = '#55E';
|
||||
};
|
||||
|
||||
$scope.ondrop = function (e) {
|
||||
const dataTransfer = e.dataTransfer || e.originalEvent.dataTransfer;
|
||||
if (dataTransfer && dataTransfer.files && dataTransfer.files.length > 0) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
$scope.stopClick(e);
|
||||
const div = e.currentTarget;
|
||||
div.style.background = '#5E5';
|
||||
setTimeout(function () { div.style.background = backgroundColor; }, 300);
|
||||
const input = div.querySelector('input');
|
||||
input.files = dataTransfer.files;
|
||||
div.querySelector('.play').innerHTML = '⏸️';
|
||||
div.querySelector('.play').disabled = false;
|
||||
div.querySelector('.stop').disabled = false;
|
||||
sendFile(dataTransfer.files[0]);
|
||||
}
|
||||
};
|
||||
|
||||
$scope.playClick = function (e) {
|
||||
const div = document.getElementById('ui_upload-' + $scope.unique);
|
||||
if ($scope.pause) {
|
||||
div.querySelector('.play').innerHTML = '⏸️';
|
||||
$scope.pause = false;
|
||||
$scope.chunkCallback.f($scope.chunkCallback.e);
|
||||
} else if (!$scope.stop) {
|
||||
$scope.pause = true;
|
||||
div.querySelector('.play').innerHTML = '▶️';
|
||||
} else {
|
||||
$scope.stopClick(e);
|
||||
const input = div.querySelector('input');
|
||||
if (input.files && input.files.length > 0) {
|
||||
div.querySelector('.play').innerHTML = '⏸️';
|
||||
div.querySelector('.play').disabled = false;
|
||||
div.querySelector('.stop').disabled = false;
|
||||
sendFile(input.files[0]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$scope.stopClick = function (e) {
|
||||
$scope.stop = true;
|
||||
$scope.pause = false;
|
||||
$scope.downstreamReady = false;
|
||||
$scope.chunkCallback = null;
|
||||
const div = document.getElementById('ui_upload-' + $scope.unique);
|
||||
div.querySelector('progress').value = 0;
|
||||
if ($scope.duration) {
|
||||
div.classList.add('done');
|
||||
div.querySelector('p.result > small').innerHTML = '' + $scope.duration + 's';
|
||||
}
|
||||
div.querySelector('.play').innerHTML = '▶️';
|
||||
div.querySelector('.play').disabled = false;
|
||||
div.querySelector('.stop').disabled = true;
|
||||
};
|
||||
|
||||
$scope.onchange = function (e) {
|
||||
$scope.stopClick(e);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an incoming node ID if the node has any input wired to it, false otherwise.
|
||||
* If filter callback is not null, then this function filters incoming nodes.
|
||||
*/
|
||||
function findInputNodeId(toNode, filter = null) {
|
||||
if (toNode && toNode._flow && toNode._flow.global) {
|
||||
const allNodes = toNode._flow.global.allNodes;
|
||||
for (const fromNodeId of Object.keys(allNodes)) {
|
||||
const fromNode = allNodes[fromNodeId];
|
||||
if (fromNode && fromNode.wires) {
|
||||
for (const wireId of Object.keys(fromNode.wires)) {
|
||||
const wire = fromNode.wires[wireId];
|
||||
for (const toNodeId of wire) {
|
||||
if (toNode.id === toNodeId && (!filter || filter(fromNode))) {
|
||||
return fromNode.id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
module.exports = function (RED) {
|
||||
let ui;
|
||||
|
||||
function uiUpload(config) {
|
||||
const node = this; // jshint ignore:line
|
||||
|
||||
// Declare the ability of this node to consume ticks from downstream for back-pressure
|
||||
node.tickConsumer = true;
|
||||
let tickDownstreamId;
|
||||
|
||||
try {
|
||||
if (!ui) {
|
||||
// load Dashboard API
|
||||
ui = RED.require('node-red-dashboard')(RED);
|
||||
}
|
||||
|
||||
RED.nodes.createNode(node, config);
|
||||
if (!config || !config.group) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Defined in https://github.com/node-red/node-red-dashboard/blob/39b095586bdbd517ffbce1efff35227283edda4c/index.js
|
||||
const done = ui.addWidget({
|
||||
node: node,
|
||||
format: html(config),
|
||||
templateScope: 'local',
|
||||
group: config.group,
|
||||
order: config.order,
|
||||
height: Math.max(config.height || 5, 3),
|
||||
emitOnlyNewValues: false,
|
||||
forwardInputMessages: false,
|
||||
storeFrontEndInputAsState: false,
|
||||
persistantFrontEndValue: false,
|
||||
|
||||
// callback to prepare the message that is emitted to the front-end
|
||||
beforeEmit: function (msg, value) {
|
||||
return { msg };
|
||||
},
|
||||
|
||||
// callback to prepare the message that is sent to the output
|
||||
beforeSend: function (msg, orig) {
|
||||
if (tickDownstreamId === undefined) {
|
||||
// Search for any output node handling ticks for back-pressure,
|
||||
// or any input node (which must take this responsability)
|
||||
tickDownstreamId = findInputNodeId(node, (n) => n && n.tickConsumer) || findInputNodeId(node);
|
||||
}
|
||||
if (!tickDownstreamId) {
|
||||
// If there is no tick provider downstream, send default tick for back-pressure
|
||||
node.receive({ tick: true });
|
||||
}
|
||||
if (orig) {
|
||||
return orig.msg;
|
||||
}
|
||||
},
|
||||
|
||||
// callback to initialize in controller
|
||||
initController: initController,
|
||||
});
|
||||
node.on('close', done);
|
||||
} catch (ex) {
|
||||
console.error(ex);
|
||||
}
|
||||
}
|
||||
|
||||
RED.nodes.registerType('ui_upload', uiUpload);
|
||||
};
|
||||
Reference in New Issue
Block a user