@rosepetal/node-red-contrib-image-tools 1.1.3 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -13
- package/node-red-contrib-image-tools/lib/node-utils.js +218 -17
- package/node-red-contrib-image-tools/nodes/blend/add-bbs.js +64 -9
- package/node-red-contrib-image-tools/nodes/blend/add-mask.js +81 -9
- package/node-red-contrib-image-tools/nodes/blend/add-masks.js +64 -8
- package/node-red-contrib-image-tools/nodes/blend/blend.js +64 -10
- package/node-red-contrib-image-tools/nodes/io/folder-in.js +12 -1
- package/node-red-contrib-image-tools/nodes/io/image-in.js +10 -2
- package/node-red-contrib-image-tools/nodes/io/image-out.js +25 -3
- package/node-red-contrib-image-tools/nodes/mix/advanced-mosaic.js +52 -26
- package/node-red-contrib-image-tools/nodes/mix/concat.js +46 -9
- package/node-red-contrib-image-tools/nodes/mix/mosaic.js +52 -15
- package/node-red-contrib-image-tools/nodes/specialized/cropBB.js +53 -5
- package/node-red-contrib-image-tools/nodes/specialized/image-align.js +54 -7
- package/node-red-contrib-image-tools/nodes/transform/color-convert.html +189 -0
- package/node-red-contrib-image-tools/nodes/transform/color-convert.js +153 -0
- package/node-red-contrib-image-tools/nodes/transform/crop.js +38 -17
- package/node-red-contrib-image-tools/nodes/transform/draw.js +28 -7
- package/node-red-contrib-image-tools/nodes/transform/filter.js +34 -15
- package/node-red-contrib-image-tools/nodes/transform/padding.js +30 -9
- package/node-red-contrib-image-tools/nodes/transform/resize.js +58 -33
- package/node-red-contrib-image-tools/nodes/transform/rotate.html +5 -5
- package/node-red-contrib-image-tools/nodes/transform/rotate.js +40 -20
- package/node-red-contrib-image-tools/package.json +2 -8
- package/package.json +2 -1
- package/rosepetal-image-engine/binding.gyp +7 -24
- package/rosepetal-image-engine/src/add-mask.cpp +2 -2
- package/rosepetal-image-engine/src/add-masks.cpp +2 -2
- package/rosepetal-image-engine/src/advanced-mosaic.cpp +7 -8
- package/rosepetal-image-engine/src/blend.cpp +2 -2
- package/rosepetal-image-engine/src/color-convert.cpp +184 -0
- package/rosepetal-image-engine/src/concat.cpp +4 -4
- package/rosepetal-image-engine/src/crop.cpp +7 -7
- package/rosepetal-image-engine/src/draw.cpp +1 -1
- package/rosepetal-image-engine/src/filter.cpp +7 -7
- package/rosepetal-image-engine/src/image-align.cpp +1 -1
- package/rosepetal-image-engine/src/main.cpp +2 -0
- package/rosepetal-image-engine/src/mosaic.cpp +8 -9
- package/rosepetal-image-engine/src/padding.cpp +8 -7
- package/rosepetal-image-engine/src/resize.cpp +105 -27
- package/rosepetal-image-engine/src/rotate.cpp +9 -12
- package/rosepetal-image-engine/src/utils.h +48 -10
- package/docs/nodes/io/array-in.md +0 -119
- package/docs/nodes/io/array-out.md +0 -150
- package/docs/nodes/io/array-select.md +0 -157
- package/docs/nodes/io/queue.md +0 -57
- package/docs/nodes/io/save-file.md +0 -30
- package/docs/nodes/util/block-detect.md +0 -46
- package/node-red-contrib-image-tools/nodes/io/array-in.html +0 -110
- package/node-red-contrib-image-tools/nodes/io/array-in.js +0 -113
- package/node-red-contrib-image-tools/nodes/io/array-out.html +0 -125
- package/node-red-contrib-image-tools/nodes/io/array-out.js +0 -213
- package/node-red-contrib-image-tools/nodes/io/array-select.html +0 -156
- package/node-red-contrib-image-tools/nodes/io/array-select.js +0 -187
- package/node-red-contrib-image-tools/nodes/io/queue.html +0 -119
- package/node-red-contrib-image-tools/nodes/io/queue.js +0 -191
- package/node-red-contrib-image-tools/nodes/io/save-file.html +0 -243
- package/node-red-contrib-image-tools/nodes/io/save-file.js +0 -440
- package/node-red-contrib-image-tools/nodes/util/block-detect.html +0 -85
- package/node-red-contrib-image-tools/nodes/util/block-detect.js +0 -136
- package/node-red-contrib-image-tools/nodes/util/clean-debug.html +0 -201
- package/node-red-contrib-image-tools/nodes/util/clean-debug.js +0 -393
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
<script type="text/javascript">
|
|
2
|
-
(function() {
|
|
3
|
-
function toggleCompleteField($complete, type) {
|
|
4
|
-
const $textInput = $complete.typedInput('input');
|
|
5
|
-
if (type === "full") {
|
|
6
|
-
if ($textInput && $textInput.length) {
|
|
7
|
-
$textInput.prop("disabled", true).addClass("disabled");
|
|
8
|
-
}
|
|
9
|
-
$("#node-input-complete-full-label").show();
|
|
10
|
-
} else {
|
|
11
|
-
if ($textInput && $textInput.length) {
|
|
12
|
-
$textInput.prop("disabled", false).removeClass("disabled");
|
|
13
|
-
}
|
|
14
|
-
$("#node-input-complete-full-label").hide();
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
RED.nodes.registerType('clean-debug', {
|
|
19
|
-
category: 'common',
|
|
20
|
-
paletteLabel: 'clean debug',
|
|
21
|
-
color: '#E2D96E',
|
|
22
|
-
inputs: 1,
|
|
23
|
-
outputs: 0,
|
|
24
|
-
icon: 'font-awesome/fa-bug',
|
|
25
|
-
align: 'right',
|
|
26
|
-
defaults: {
|
|
27
|
-
name: { value: "" },
|
|
28
|
-
active: { value: true },
|
|
29
|
-
tosidebar: { value: true },
|
|
30
|
-
console: { value: false },
|
|
31
|
-
complete: { value: "payload" },
|
|
32
|
-
targetType: { value: "msg" },
|
|
33
|
-
clean: { value: true }
|
|
34
|
-
},
|
|
35
|
-
label: function() {
|
|
36
|
-
if (this.name) {
|
|
37
|
-
return this.name;
|
|
38
|
-
}
|
|
39
|
-
return this.clean === false ? "debug" : "clean debug";
|
|
40
|
-
},
|
|
41
|
-
labelStyle: function() {
|
|
42
|
-
return this.name ? "node_label_italic" : "";
|
|
43
|
-
},
|
|
44
|
-
button: {
|
|
45
|
-
toggle: "active",
|
|
46
|
-
visible: function() {
|
|
47
|
-
return true;
|
|
48
|
-
},
|
|
49
|
-
onclick: function() {
|
|
50
|
-
var node = this;
|
|
51
|
-
var desiredState = node.active;
|
|
52
|
-
|
|
53
|
-
sendCleanDebugToggle(node, desiredState, function() {
|
|
54
|
-
var historyEvent = {
|
|
55
|
-
t: 'edit',
|
|
56
|
-
node: node,
|
|
57
|
-
changes: {
|
|
58
|
-
active: !node.active
|
|
59
|
-
},
|
|
60
|
-
dirty: node.dirty,
|
|
61
|
-
changed: node.changed,
|
|
62
|
-
callback: function(ev) {
|
|
63
|
-
sendCleanDebugToggle(ev.node, ev.node.active);
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
node.changed = true;
|
|
68
|
-
node.dirty = true;
|
|
69
|
-
RED.nodes.dirty(true);
|
|
70
|
-
RED.history.push(historyEvent);
|
|
71
|
-
RED.view.redraw();
|
|
72
|
-
}, function() {
|
|
73
|
-
node.active = !node.active;
|
|
74
|
-
RED.view.redraw();
|
|
75
|
-
RED.notify("Failed to update Clean Debug state", "error");
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
},
|
|
79
|
-
oneditprepare: function() {
|
|
80
|
-
const $complete = $("#node-input-complete");
|
|
81
|
-
$complete.typedInput({
|
|
82
|
-
default: 'msg',
|
|
83
|
-
types: [
|
|
84
|
-
'msg',
|
|
85
|
-
'flow',
|
|
86
|
-
'global',
|
|
87
|
-
'str',
|
|
88
|
-
'num',
|
|
89
|
-
'bool',
|
|
90
|
-
'json',
|
|
91
|
-
'bin',
|
|
92
|
-
'date',
|
|
93
|
-
'jsonata',
|
|
94
|
-
'env',
|
|
95
|
-
{
|
|
96
|
-
value: 'full',
|
|
97
|
-
label: 'complete msg object',
|
|
98
|
-
hasValue: false
|
|
99
|
-
}
|
|
100
|
-
],
|
|
101
|
-
typeField: "#node-input-targetType"
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
toggleCompleteField($complete, $complete.typedInput('type'));
|
|
105
|
-
|
|
106
|
-
$complete.on("change", function() {
|
|
107
|
-
toggleCompleteField($complete, $complete.typedInput('type'));
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
$("#node-input-tosidebar").prop("checked", this.tosidebar !== false);
|
|
111
|
-
$("#node-input-console").prop("checked", this.console === true);
|
|
112
|
-
$("#node-input-clean").prop("checked", this.clean !== false);
|
|
113
|
-
},
|
|
114
|
-
oneditsave: function() {
|
|
115
|
-
this.tosidebar = $("#node-input-tosidebar").is(":checked");
|
|
116
|
-
this.console = $("#node-input-console").is(":checked");
|
|
117
|
-
this.clean = $("#node-input-clean").is(":checked");
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
})();
|
|
121
|
-
</script>
|
|
122
|
-
|
|
123
|
-
<script type="text/x-red" data-template-name="clean-debug">
|
|
124
|
-
<div class="form-row">
|
|
125
|
-
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
126
|
-
<input type="text" id="node-input-name" placeholder="Name">
|
|
127
|
-
</div>
|
|
128
|
-
|
|
129
|
-
<div class="form-row">
|
|
130
|
-
<label for="node-input-complete"><i class="fa fa-dot-circle-o"></i> Output</label>
|
|
131
|
-
<input type="text" id="node-input-complete" style="width: 70%;">
|
|
132
|
-
<input type="hidden" id="node-input-targetType">
|
|
133
|
-
<span id="node-input-complete-full-label" style="display: none;">complete msg object</span>
|
|
134
|
-
</div>
|
|
135
|
-
|
|
136
|
-
<div class="form-row">
|
|
137
|
-
<label></label>
|
|
138
|
-
<input type="checkbox" id="node-input-tosidebar" checked>
|
|
139
|
-
<label for="node-input-tosidebar" style="width: auto;">Send to debug sidebar</label>
|
|
140
|
-
</div>
|
|
141
|
-
|
|
142
|
-
<div class="form-row">
|
|
143
|
-
<label></label>
|
|
144
|
-
<input type="checkbox" id="node-input-console">
|
|
145
|
-
<label for="node-input-console" style="width: auto;">Also log to console</label>
|
|
146
|
-
</div>
|
|
147
|
-
|
|
148
|
-
<div class="form-row">
|
|
149
|
-
<label></label>
|
|
150
|
-
<input type="checkbox" id="node-input-clean" checked>
|
|
151
|
-
<label for="node-input-clean" style="width: auto;">Clean heavy payloads (images/buffers)</label>
|
|
152
|
-
</div>
|
|
153
|
-
</script>
|
|
154
|
-
|
|
155
|
-
<script type="text/x-red" data-help-name="clean-debug">
|
|
156
|
-
<p>An enhanced drop-in replacement for the core Debug node that filters out heavy binary/image payloads by default to keep the debug sidebar responsive.</p>
|
|
157
|
-
|
|
158
|
-
<h3>Details</h3>
|
|
159
|
-
<p>The Clean Debug node mirrors the behaviour of the standard Debug node while adding an optional cleaning step that replaces Buffers, typed arrays, data URLs and large Base64 strings with short placeholders.</p>
|
|
160
|
-
|
|
161
|
-
<h3>Properties</h3>
|
|
162
|
-
<dl class="message-properties">
|
|
163
|
-
<dt>Output<span class="property-type">typed input</span></dt>
|
|
164
|
-
<dd>Select the message property (or expression) to show in the debug sidebar. Choose <strong>complete msg object</strong> to inspect the whole message.</dd>
|
|
165
|
-
<dt>Send to debug sidebar<span class="property-type">boolean</span></dt>
|
|
166
|
-
<dd>Publish the result to the editor sidebar. Disable if you only want console/status output.</dd>
|
|
167
|
-
<dt>Also log to console<span class="property-type">boolean</span></dt>
|
|
168
|
-
<dd>Write the formatted output to the Node-RED runtime log.</dd>
|
|
169
|
-
<dt>Clean heavy payloads<span class="property-type">boolean</span></dt>
|
|
170
|
-
<dd>When enabled (default), large Buffers, Base64 strings and data URLs are replaced with concise placeholders so they do not flood the UI.</dd>
|
|
171
|
-
<dt>Enabled<span class="property-type">boolean</span></dt>
|
|
172
|
-
<dd>Temporarily disable the node without removing it from your flow.</dd>
|
|
173
|
-
</dl>
|
|
174
|
-
|
|
175
|
-
<h3>Notes</h3>
|
|
176
|
-
<ul>
|
|
177
|
-
<li>Disabling the clean option restores the exact behaviour of the built-in Debug node.</li>
|
|
178
|
-
<li>The cleaning step only affects what is displayed; the original message object is left untouched.</li>
|
|
179
|
-
</ul>
|
|
180
|
-
</script>
|
|
181
|
-
|
|
182
|
-
<script type="text/javascript">
|
|
183
|
-
function sendCleanDebugToggle(node, desiredState, onSuccess, onError) {
|
|
184
|
-
$.ajax({
|
|
185
|
-
url: "clean-debug/" + node.id,
|
|
186
|
-
type: "POST",
|
|
187
|
-
data: JSON.stringify({ active: desiredState }),
|
|
188
|
-
contentType: "application/json; charset=utf-8",
|
|
189
|
-
success: function(resp) {
|
|
190
|
-
if (typeof onSuccess === "function") {
|
|
191
|
-
onSuccess(resp);
|
|
192
|
-
}
|
|
193
|
-
},
|
|
194
|
-
error: function(jqXHR, textStatus, errorThrown) {
|
|
195
|
-
if (typeof onError === "function") {
|
|
196
|
-
onError(jqXHR, textStatus, errorThrown);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
</script>
|
|
@@ -1,393 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const util = require("util");
|
|
4
|
-
|
|
5
|
-
module.exports = function registerCleanDebugNode(RED) {
|
|
6
|
-
const DEFAULT_DEBUG_MAX_LENGTH = (RED.settings && RED.settings.debugMaxLength) || 1000;
|
|
7
|
-
const BUFFER_PREVIEW_BYTES = Math.max(DEFAULT_DEBUG_MAX_LENGTH, 512);
|
|
8
|
-
|
|
9
|
-
function CleanDebugNode(config) {
|
|
10
|
-
RED.nodes.createNode(this, config);
|
|
11
|
-
const node = this;
|
|
12
|
-
|
|
13
|
-
node.name = config.name;
|
|
14
|
-
node.active = config.active !== false;
|
|
15
|
-
node.tosidebar = config.tosidebar !== false;
|
|
16
|
-
node.console = !!config.console;
|
|
17
|
-
node.complete = (config.complete && config.complete !== "") ? config.complete : "payload";
|
|
18
|
-
node.targetType = config.targetType || "msg";
|
|
19
|
-
node.clean = config.clean !== false; // default true
|
|
20
|
-
|
|
21
|
-
node.on("input", function onInput(msg, send, done) {
|
|
22
|
-
if (!node.active) {
|
|
23
|
-
if (done) {
|
|
24
|
-
done();
|
|
25
|
-
}
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
resolveDebugValue(msg)
|
|
30
|
-
.then((resolved) => handleDebugOutput(msg, resolved))
|
|
31
|
-
.then(() => {
|
|
32
|
-
if (done) {
|
|
33
|
-
done();
|
|
34
|
-
}
|
|
35
|
-
})
|
|
36
|
-
.catch((err) => {
|
|
37
|
-
node.error(err && err.message ? err.message : err, msg);
|
|
38
|
-
if (done) {
|
|
39
|
-
done(err);
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Resolve the configured value the node should display.
|
|
46
|
-
* @param {object} msg
|
|
47
|
-
* @returns {Promise<*>}
|
|
48
|
-
*/
|
|
49
|
-
function resolveDebugValue(msg) {
|
|
50
|
-
if (node.targetType === "full" || node.targetType === "complete") {
|
|
51
|
-
return Promise.resolve(RED.util.cloneMessage(msg));
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (node.targetType === "msg" || node.targetType === "msgProperty") {
|
|
55
|
-
const property = node.complete || "payload";
|
|
56
|
-
try {
|
|
57
|
-
return Promise.resolve(RED.util.getMessageProperty(msg, property));
|
|
58
|
-
} catch (err) {
|
|
59
|
-
return Promise.reject(err);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return new Promise((resolve, reject) => {
|
|
64
|
-
const property = node.complete || "";
|
|
65
|
-
RED.util.evaluateNodeProperty(property, node.targetType, node, msg, (err, value) => {
|
|
66
|
-
if (err) {
|
|
67
|
-
reject(err);
|
|
68
|
-
} else {
|
|
69
|
-
resolve(value);
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Emit to the configured outputs (sidebar/console).
|
|
77
|
-
* @param {object} msg
|
|
78
|
-
* @param {*} value
|
|
79
|
-
*/
|
|
80
|
-
function handleDebugOutput(msg, value) {
|
|
81
|
-
const mode = node.clean ? "clean" : "full";
|
|
82
|
-
const preparedValue = sanitiseValue(value, { mode });
|
|
83
|
-
|
|
84
|
-
if (node.console) {
|
|
85
|
-
const consoleValue = node.clean ? preparedValue : value;
|
|
86
|
-
const formatted = formatForConsole(consoleValue);
|
|
87
|
-
node.log(formatted);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (node.tosidebar !== false) {
|
|
91
|
-
publishToSidebar(msg, preparedValue);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Publish the debug payload to the editor sidebar.
|
|
97
|
-
* @param {object} msg
|
|
98
|
-
* @param {*} value
|
|
99
|
-
*/
|
|
100
|
-
function publishToSidebar(msg, value) {
|
|
101
|
-
if (!RED.comms || typeof RED.comms.publish !== "function") {
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const format = detectValueType(value);
|
|
106
|
-
const debugMessage = {
|
|
107
|
-
id: node.id,
|
|
108
|
-
z: node.z,
|
|
109
|
-
_alias: node._alias,
|
|
110
|
-
name: node.name,
|
|
111
|
-
topic: msg && msg.topic,
|
|
112
|
-
property: node.targetType === "full" ? "msg" : node.complete,
|
|
113
|
-
propertyType: node.targetType,
|
|
114
|
-
clean: node.clean,
|
|
115
|
-
format,
|
|
116
|
-
msg: value,
|
|
117
|
-
_msgid: msg && msg._msgid
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
RED.comms.publish("debug", debugMessage);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Produce a lightweight clone that is safe to ship to the editor.
|
|
126
|
-
* @param {*} input
|
|
127
|
-
* @param {object} [options]
|
|
128
|
-
* @param {"clean"|"full"} [options.mode="clean"]
|
|
129
|
-
* @returns {*}
|
|
130
|
-
*/
|
|
131
|
-
function sanitiseValue(input, options = {}) {
|
|
132
|
-
const mode = options.mode === "full" ? "full" : "clean";
|
|
133
|
-
const opts = {
|
|
134
|
-
maxDepth: options.maxDepth || 6,
|
|
135
|
-
maxArrayLength: options.maxArrayLength || (mode === "clean" ? 50 : 100),
|
|
136
|
-
maxObjectKeys: options.maxObjectKeys || (mode === "clean" ? 60 : 120),
|
|
137
|
-
maxStringLength: options.maxStringLength || (mode === "clean" ? 2048 : DEFAULT_DEBUG_MAX_LENGTH),
|
|
138
|
-
bufferPreviewLength: options.bufferPreviewLength || (mode === "clean" ? 0 : BUFFER_PREVIEW_BYTES),
|
|
139
|
-
mode
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
const seen = new WeakMap();
|
|
143
|
-
|
|
144
|
-
function helper(value, depth, path) {
|
|
145
|
-
if (value === null || value === undefined) {
|
|
146
|
-
return value;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
const valueType = typeof value;
|
|
150
|
-
if (valueType === "number" || valueType === "boolean") {
|
|
151
|
-
return value;
|
|
152
|
-
}
|
|
153
|
-
if (valueType === "bigint") {
|
|
154
|
-
return `${value.toString()}n`;
|
|
155
|
-
}
|
|
156
|
-
if (valueType === "string") {
|
|
157
|
-
return sanitiseString(value, opts);
|
|
158
|
-
}
|
|
159
|
-
if (valueType === "symbol") {
|
|
160
|
-
return value.toString();
|
|
161
|
-
}
|
|
162
|
-
if (valueType === "function") {
|
|
163
|
-
return `[Function ${value.name || "anonymous"}]`;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
if (Buffer.isBuffer(value)) {
|
|
167
|
-
return encodeBuffer(value, opts);
|
|
168
|
-
}
|
|
169
|
-
if (ArrayBuffer.isView(value) && !(value instanceof DataView)) {
|
|
170
|
-
return encodeTypedArray(value, opts);
|
|
171
|
-
}
|
|
172
|
-
if (value instanceof ArrayBuffer) {
|
|
173
|
-
return encodeTypedArray(new Uint8Array(value), opts);
|
|
174
|
-
}
|
|
175
|
-
if (value instanceof Date) {
|
|
176
|
-
return value.toISOString();
|
|
177
|
-
}
|
|
178
|
-
if (value instanceof RegExp) {
|
|
179
|
-
return value.toString();
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
if (typeof value === "object") {
|
|
183
|
-
if (seen.has(value)) {
|
|
184
|
-
return `[Circular ~${seen.get(value)}]`;
|
|
185
|
-
}
|
|
186
|
-
seen.set(value, path || "~");
|
|
187
|
-
|
|
188
|
-
if (value.type === "Buffer" && Array.isArray(value.data)) {
|
|
189
|
-
if (opts.mode === "clean") {
|
|
190
|
-
return createPlaceholder("Buffer", `${value.data.length} bytes`);
|
|
191
|
-
}
|
|
192
|
-
return encodeBuffer(Buffer.from(value.data), opts);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
if (depth >= opts.maxDepth) {
|
|
196
|
-
if (Array.isArray(value)) {
|
|
197
|
-
return `[Array(${value.length})]`;
|
|
198
|
-
}
|
|
199
|
-
return `[Object with ${Object.keys(value).length} keys]`;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
if (Array.isArray(value)) {
|
|
203
|
-
const result = [];
|
|
204
|
-
const len = Math.min(value.length, opts.maxArrayLength);
|
|
205
|
-
for (let i = 0; i < len; i += 1) {
|
|
206
|
-
const childPath = `${path || "~"}[${i}]`;
|
|
207
|
-
result.push(helper(value[i], depth + 1, childPath));
|
|
208
|
-
}
|
|
209
|
-
if (value.length > opts.maxArrayLength) {
|
|
210
|
-
result.push(`… ${value.length - opts.maxArrayLength} more items`);
|
|
211
|
-
}
|
|
212
|
-
return result;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
const keys = Object.keys(value);
|
|
216
|
-
const clone = {};
|
|
217
|
-
const limit = Math.min(keys.length, opts.maxObjectKeys);
|
|
218
|
-
|
|
219
|
-
for (let i = 0; i < limit; i += 1) {
|
|
220
|
-
const key = keys[i];
|
|
221
|
-
const childPath = path ? `${path}.${key}` : key;
|
|
222
|
-
clone[key] = helper(value[key], depth + 1, childPath);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
if (keys.length > opts.maxObjectKeys) {
|
|
226
|
-
clone.__cleanDebugTruncated = true;
|
|
227
|
-
clone.__cleanDebugNote = `${keys.length - opts.maxObjectKeys} more keys not shown`;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
return clone;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
return value;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
return helper(input, 0, "");
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* Sanitise long/base64 strings with heuristics.
|
|
241
|
-
* @param {string} value
|
|
242
|
-
* @param {object} opts
|
|
243
|
-
*/
|
|
244
|
-
function sanitiseString(value, opts) {
|
|
245
|
-
const trimmed = value.trim();
|
|
246
|
-
if (opts.mode === "clean" && trimmed.startsWith("data:image/")) {
|
|
247
|
-
return createPlaceholder("DataImage", `${value.length} chars`);
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
if (opts.mode === "clean" && isLikelyBase64(trimmed)) {
|
|
251
|
-
return createPlaceholder("Base64", `${value.length} chars`);
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
if (value.length > opts.maxStringLength) {
|
|
255
|
-
return `${value.slice(0, opts.maxStringLength)}… [truncated ${value.length - opts.maxStringLength} chars]`;
|
|
256
|
-
}
|
|
257
|
-
return value;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
* Encode a buffer so the UI can inspect it without loading all bytes.
|
|
262
|
-
* @param {Buffer} buffer
|
|
263
|
-
* @param {object} opts
|
|
264
|
-
*/
|
|
265
|
-
function encodeBuffer(buffer, opts) {
|
|
266
|
-
if (opts.mode === "clean" || opts.bufferPreviewLength <= 0) {
|
|
267
|
-
return createPlaceholder("Buffer", `${buffer.length} bytes`);
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
const previewLength = Math.min(buffer.length, opts.bufferPreviewLength);
|
|
271
|
-
const slice = buffer.slice(0, previewLength).toJSON();
|
|
272
|
-
slice.length = buffer.length;
|
|
273
|
-
if (previewLength < buffer.length) {
|
|
274
|
-
slice.__cleanDebugTruncated = true;
|
|
275
|
-
slice.__cleanDebugNote = `${buffer.length - previewLength} more bytes not shown`;
|
|
276
|
-
}
|
|
277
|
-
return slice;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
/**
|
|
281
|
-
* Encode typed arrays safely.
|
|
282
|
-
* @param {TypedArray} view
|
|
283
|
-
* @param {object} opts
|
|
284
|
-
*/
|
|
285
|
-
function encodeTypedArray(view, opts) {
|
|
286
|
-
if (opts.mode === "clean") {
|
|
287
|
-
const ctor = view.constructor && view.constructor.name ? view.constructor.name : "TypedArray";
|
|
288
|
-
return createPlaceholder(ctor, `${view.length} items`);
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
const limit = Math.min(view.length, opts.maxArrayLength);
|
|
292
|
-
const data = [];
|
|
293
|
-
for (let i = 0; i < limit; i += 1) {
|
|
294
|
-
data.push(view[i]);
|
|
295
|
-
}
|
|
296
|
-
const descriptor = {
|
|
297
|
-
type: view.constructor && view.constructor.name ? view.constructor.name : "TypedArray",
|
|
298
|
-
length: view.length,
|
|
299
|
-
data
|
|
300
|
-
};
|
|
301
|
-
if (limit < view.length) {
|
|
302
|
-
descriptor.__cleanDebugTruncated = true;
|
|
303
|
-
descriptor.__cleanDebugNote = `${view.length - limit} more items not shown`;
|
|
304
|
-
}
|
|
305
|
-
return descriptor;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
/**
|
|
309
|
-
* Detect base64-ish strings that are long enough to be heavy payloads.
|
|
310
|
-
* @param {string} value
|
|
311
|
-
*/
|
|
312
|
-
function isLikelyBase64(value) {
|
|
313
|
-
if (value.length < 512) {
|
|
314
|
-
return false;
|
|
315
|
-
}
|
|
316
|
-
if (value.length % 4 !== 0) {
|
|
317
|
-
return false;
|
|
318
|
-
}
|
|
319
|
-
if (!/^[A-Za-z0-9+/=\s]+$/.test(value)) {
|
|
320
|
-
return false;
|
|
321
|
-
}
|
|
322
|
-
const paddingRatio = (value.match(/=/g) || []).length / value.length;
|
|
323
|
-
return paddingRatio < 0.1;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
/**
|
|
327
|
-
* Generate placeholder string.
|
|
328
|
-
*/
|
|
329
|
-
function createPlaceholder(type, detail) {
|
|
330
|
-
return `[${type} withheld: ${detail}]`;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
/**
|
|
334
|
-
* Detect broad value type to help the editor render icons.
|
|
335
|
-
* @param {*} value
|
|
336
|
-
*/
|
|
337
|
-
function detectValueType(value) {
|
|
338
|
-
if (value === null) {
|
|
339
|
-
return "null";
|
|
340
|
-
}
|
|
341
|
-
if (value && typeof value === "object" && value.type === "Buffer" && Array.isArray(value.data)) {
|
|
342
|
-
return "buffer";
|
|
343
|
-
}
|
|
344
|
-
const t = typeof value;
|
|
345
|
-
if (t === "string" || t === "number" || t === "boolean" || t === "bigint") {
|
|
346
|
-
return t;
|
|
347
|
-
}
|
|
348
|
-
if (Array.isArray(value)) {
|
|
349
|
-
return "array";
|
|
350
|
-
}
|
|
351
|
-
if (value instanceof Date) {
|
|
352
|
-
return "date";
|
|
353
|
-
}
|
|
354
|
-
return "object";
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
/**
|
|
358
|
-
* Format for console/log output.
|
|
359
|
-
* @param {*} value
|
|
360
|
-
*/
|
|
361
|
-
function formatForConsole(value) {
|
|
362
|
-
return util.inspect(value, {
|
|
363
|
-
depth: 5,
|
|
364
|
-
maxArrayLength: 10,
|
|
365
|
-
breakLength: 120,
|
|
366
|
-
maxStringLength: DEFAULT_DEBUG_MAX_LENGTH
|
|
367
|
-
});
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
RED.nodes.registerType("clean-debug", CleanDebugNode);
|
|
371
|
-
|
|
372
|
-
RED.httpAdmin.post("/clean-debug/:id", RED.auth.needsPermission("flows.write"), function(req, res) {
|
|
373
|
-
const node = RED.nodes.getNode(req.params.id);
|
|
374
|
-
if (!node) {
|
|
375
|
-
res.sendStatus(404);
|
|
376
|
-
return;
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
if (typeof node.active === "undefined") {
|
|
380
|
-
node.active = true;
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
let desiredState;
|
|
384
|
-
if (req.body && Object.prototype.hasOwnProperty.call(req.body, "active")) {
|
|
385
|
-
desiredState = !!req.body.active;
|
|
386
|
-
} else {
|
|
387
|
-
desiredState = !node.active;
|
|
388
|
-
}
|
|
389
|
-
node.active = desiredState;
|
|
390
|
-
|
|
391
|
-
res.json({ active: node.active });
|
|
392
|
-
});
|
|
393
|
-
};
|