@gregoriusrippenstein/node-red-contrib-introspection 0.2.5 → 0.2.9
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/nodes/15-screenshot.html +74 -25
- package/nodes/20-orphans.html +16 -2
- package/nodes/45-get-flows.js +46 -57
- package/package.json +5 -2
package/nodes/15-screenshot.html
CHANGED
|
@@ -1,10 +1,24 @@
|
|
|
1
1
|
<script type="text/javascript">
|
|
2
|
-
function
|
|
3
|
-
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
|
|
2
|
+
function nr_intro_generate_svg_3_1( callbackWithSvgCode ) {
|
|
3
|
+
//****
|
|
4
|
+
// Node-RED 3.1.x has multiple SVGs all over the place, so we
|
|
5
|
+
// need to look for the one with 8000x8000.
|
|
6
|
+
// Tested this on Node-RED 3.1.0.beta.4 - dunno about other 3.1.x.beta.y
|
|
7
|
+
//****
|
|
7
8
|
|
|
9
|
+
handleSvgObject( $($('svg[width=8000]')[0]), callbackWithSvgCode );
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function nr_intro_generate_svg_3_0( callbackWithSvgCode ) {
|
|
13
|
+
//****
|
|
14
|
+
// for Node-RED v3.0.x (well 3.0.2 tested, dunno about 3.0.1)
|
|
15
|
+
//****
|
|
16
|
+
|
|
17
|
+
handleSvgObject( $($('svg')[0]), callbackWithSvgCode);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
function handleSvgObject( origSvg, callbackWithSvgCode ) {
|
|
8
22
|
// the DOMParser of Firefox does not like foreignObjects, so remove them.
|
|
9
23
|
// Correction: DOMParser doesn't mind foreignObjects as long as there is
|
|
10
24
|
// any HTML/<img>-tags in the foreignObjects.,,, of course, image tags
|
|
@@ -155,21 +169,34 @@
|
|
|
155
169
|
// inline image data. Image types supported: Jpeg, Png and Svg.
|
|
156
170
|
var imageColl = doc.getElementsByTagName("image");
|
|
157
171
|
|
|
172
|
+
var imageCache = {};
|
|
173
|
+
|
|
158
174
|
var getDataAndCallbackWhenDone = (elem, cntr, cb) => {
|
|
159
|
-
var
|
|
175
|
+
var hrefSrc = elem.getAttribute("xlink:href");
|
|
176
|
+
|
|
177
|
+
var postfix = hrefSrc.substr(-4,4).toLowerCase();
|
|
178
|
+
var fileType = {
|
|
179
|
+
".jpg": "jpeg",
|
|
180
|
+
"jpeg": "jpeg",
|
|
181
|
+
".png": "png",
|
|
182
|
+
".svg": "svg+xml",
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
if ( imageCache[hrefSrc] ) {
|
|
186
|
+
elem.setAttribute(
|
|
187
|
+
"xlink:href",
|
|
188
|
+
"data:image/" + fileType[postfix] + ";base64," + imageCache[hrefSrc]
|
|
189
|
+
);
|
|
190
|
+
return cb(cntr-1);
|
|
191
|
+
}
|
|
160
192
|
|
|
161
193
|
switch(postfix){
|
|
162
194
|
case ".jpg":
|
|
163
195
|
case "jpeg":
|
|
164
196
|
case ".png":
|
|
165
|
-
var fileType = {
|
|
166
|
-
".jpg": "jpeg",
|
|
167
|
-
"jpeg": "jpeg",
|
|
168
|
-
".png": "png"
|
|
169
|
-
};
|
|
170
|
-
|
|
171
197
|
var oReq = new XMLHttpRequest();
|
|
172
|
-
|
|
198
|
+
|
|
199
|
+
oReq.open("GET", hrefSrc, true);
|
|
173
200
|
oReq.responseType = "arraybuffer";
|
|
174
201
|
|
|
175
202
|
var arrayBufferToBase64 = ( buffer ) => {
|
|
@@ -185,9 +212,11 @@
|
|
|
185
212
|
oReq.onload = function (oEvent) {
|
|
186
213
|
var arrayBuffer = oReq.response; // Note: not oReq.responseText
|
|
187
214
|
if (arrayBuffer) {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
215
|
+
var b64Data = arrayBufferToBase64(arrayBuffer);
|
|
216
|
+
imageCache[hrefSrc] = b64Data;
|
|
217
|
+
elem.setAttribute(
|
|
218
|
+
"xlink:href", "data:image/"+fileType[postfix]+";base64,"+b64Data
|
|
219
|
+
);
|
|
191
220
|
cb(cntr-1)
|
|
192
221
|
} else {
|
|
193
222
|
cb(cntr-1)
|
|
@@ -198,11 +227,12 @@
|
|
|
198
227
|
break;
|
|
199
228
|
|
|
200
229
|
case ".svg":
|
|
201
|
-
$.get(
|
|
230
|
+
$.get( hrefSrc, function(data) {
|
|
202
231
|
const serializer = new XMLSerializer();
|
|
232
|
+
var b64Data = btoa(serializer.serializeToString(data));
|
|
233
|
+
imageCache[hrefSrc] = b64Data;
|
|
203
234
|
elem.setAttribute( "xlink:href",
|
|
204
|
-
"data:image/svg+xml;base64," +
|
|
205
|
-
btoa(serializer.serializeToString(data)));
|
|
235
|
+
"data:image/svg+xml;base64," + b64Data);
|
|
206
236
|
cb(cntr-1)
|
|
207
237
|
});
|
|
208
238
|
break;
|
|
@@ -211,8 +241,8 @@
|
|
|
211
241
|
|
|
212
242
|
var cb = (cntr) => {
|
|
213
243
|
if ( cntr < 0 ) {
|
|
214
|
-
|
|
215
|
-
callbackWithSvgCode(
|
|
244
|
+
delete imageCache;
|
|
245
|
+
callbackWithSvgCode((new XMLSerializer()).serializeToString(doc));
|
|
216
246
|
} else {
|
|
217
247
|
getDataAndCallbackWhenDone( imageColl.item(cntr), cntr, cb );
|
|
218
248
|
}
|
|
@@ -223,11 +253,30 @@
|
|
|
223
253
|
imageColl.length-1,
|
|
224
254
|
cb );
|
|
225
255
|
} else {
|
|
226
|
-
|
|
227
|
-
callbackWithSvgCode(
|
|
256
|
+
delete imageCache;
|
|
257
|
+
callbackWithSvgCode( (new XMLSerializer()).serializeToString(doc) );
|
|
228
258
|
}
|
|
229
259
|
};
|
|
230
260
|
|
|
261
|
+
function generatorFunctionForVersion(version) {
|
|
262
|
+
var major = version[0]; // 3.0.x or 3.1.x --> making assumptions that
|
|
263
|
+
var minor = version[2]; // between minor version nothing changed
|
|
264
|
+
|
|
265
|
+
var dummy = (cd) => {
|
|
266
|
+
if ( cb ) {
|
|
267
|
+
var svgData = '<?xml version="1.0" encoding="UTF-8" standalone="no"?><svg width="10" height="10" pointer-events="all" style="cursor: crosshair; touch-action: none;" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"></svg>'
|
|
268
|
+
cb(svgData);
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
if ( major == "3" ) {
|
|
273
|
+
if ( minor == "0" ) { return nr_intro_generate_svg_3_0; }
|
|
274
|
+
if ( minor == "1" ) { return nr_intro_generate_svg_3_1; }
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
return dummy;
|
|
278
|
+
};
|
|
279
|
+
|
|
231
280
|
/*
|
|
232
281
|
When the server side of this node is triggered, it posts a message on
|
|
233
282
|
the communication channel. The frontend node captures that message,
|
|
@@ -242,7 +291,7 @@
|
|
|
242
291
|
}
|
|
243
292
|
|
|
244
293
|
var notification = data.notification;
|
|
245
|
-
|
|
294
|
+
generatorFunctionForVersion(RED.settings.version)( (svgdata) => {
|
|
246
295
|
$.ajax({
|
|
247
296
|
type: "POST",
|
|
248
297
|
url: "/screenshot",
|
|
@@ -346,7 +395,7 @@
|
|
|
346
395
|
|
|
347
396
|
this.editor.setValue( "Please wait, screenshot being prepared ..." );
|
|
348
397
|
|
|
349
|
-
|
|
398
|
+
generatorFunctionForVersion(RED.settings.version)( (svgdata) => {
|
|
350
399
|
that.editor.setValue( svgdata );
|
|
351
400
|
});
|
|
352
401
|
|
package/nodes/20-orphans.html
CHANGED
|
@@ -135,6 +135,19 @@
|
|
|
135
135
|
});
|
|
136
136
|
|
|
137
137
|
dirList.treeList('data',items);
|
|
138
|
+
|
|
139
|
+
$("#node-input-back-home-but").on("click", function(e) {
|
|
140
|
+
e.preventDefault();
|
|
141
|
+
var nde = RED.nodes.node(node.id);
|
|
142
|
+
if ( nde ) {
|
|
143
|
+
RED.workspaces.show(nde.z,false,false,true);
|
|
144
|
+
nde.highlighted = true;
|
|
145
|
+
nde.dirty = true;
|
|
146
|
+
RED.view.reveal(nde.id,true)
|
|
147
|
+
RED.view.redraw();
|
|
148
|
+
RED.tray.close();
|
|
149
|
+
}
|
|
150
|
+
});
|
|
138
151
|
},
|
|
139
152
|
|
|
140
153
|
oneditsave: function() {
|
|
@@ -148,8 +161,9 @@
|
|
|
148
161
|
</script>
|
|
149
162
|
|
|
150
163
|
<script type="text/html" data-template-name="Orphans">
|
|
151
|
-
<div class="form-row">
|
|
152
|
-
<
|
|
164
|
+
<div class="form-row node-input-target-row">
|
|
165
|
+
<button id="node-input-back-home-but"
|
|
166
|
+
class="red-ui-button">Back Home</button>
|
|
153
167
|
</div>
|
|
154
168
|
|
|
155
169
|
<div class="form-row node-input-target-row node-input-target-list-row" style="position: relative; min-height: 100px">
|
package/nodes/45-get-flows.js
CHANGED
|
@@ -11,13 +11,41 @@ module.exports = function(RED) {
|
|
|
11
11
|
|
|
12
12
|
node.on("input", function(msg, send, done) {
|
|
13
13
|
var os = require('os');
|
|
14
|
-
var got = require('got');
|
|
15
14
|
|
|
16
15
|
var baseUrl = "http://" + os.hostname() + ":" + RED.settings.get("uiPort");
|
|
17
16
|
if ( RED.settings.get("httpAdminRoot") != "/" ) {
|
|
18
17
|
baseUrl += RED.settings.get("httpAdminRoot");
|
|
19
18
|
}
|
|
20
19
|
|
|
20
|
+
var getFlows = (hdrs, got) => {
|
|
21
|
+
got.get( baseUrl + "/flows", {
|
|
22
|
+
headers: {
|
|
23
|
+
"Node-RED-API-Version": cfg.flowVersion,
|
|
24
|
+
...hdrs
|
|
25
|
+
}
|
|
26
|
+
}).then( res => {
|
|
27
|
+
var bodySize = res.body.length;
|
|
28
|
+
|
|
29
|
+
send({
|
|
30
|
+
...msg,
|
|
31
|
+
payload: res.body
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
node.status({fill:"green",shape:"dot",text:"Good"});
|
|
35
|
+
setTimeout( function() {
|
|
36
|
+
node.status({
|
|
37
|
+
fill: "blue",
|
|
38
|
+
shape: "dot",
|
|
39
|
+
text: "Flow size: " + bodySize
|
|
40
|
+
})
|
|
41
|
+
}, 450);
|
|
42
|
+
|
|
43
|
+
}).catch( err => {
|
|
44
|
+
node.status({fill:"red",shape:"dot",text:"Failed"});
|
|
45
|
+
node.error(err)
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
|
|
21
49
|
if ( cfg.useAuthentication ) {
|
|
22
50
|
var username = undefined;
|
|
23
51
|
var password = undefined;
|
|
@@ -48,41 +76,26 @@ module.exports = function(RED) {
|
|
|
48
76
|
"password": password
|
|
49
77
|
}
|
|
50
78
|
|
|
51
|
-
got.
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
node.status({fill:"blue",shape:"dot",text:"Requesting flows"});
|
|
55
|
-
|
|
56
|
-
var access_token = JSON.parse(res.body).access_token;
|
|
57
|
-
got.get( baseUrl + "/flows", {
|
|
58
|
-
headers: {
|
|
59
|
-
"Node-RED-API-Version": cfg.flowVersion,
|
|
60
|
-
"Authorization": "Bearer " + access_token
|
|
61
|
-
}
|
|
79
|
+
import('got').then( (module) => {
|
|
80
|
+
module.got.post( baseUrl + "/auth/token", {
|
|
81
|
+
json: data
|
|
62
82
|
}).then( res => {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
payload: res.body
|
|
83
|
+
node.status({
|
|
84
|
+
fill:"blue",
|
|
85
|
+
shape:"dot",
|
|
86
|
+
text:"Requesting flows"
|
|
68
87
|
});
|
|
69
88
|
|
|
70
|
-
|
|
71
|
-
setTimeout( function() {
|
|
72
|
-
node.status({
|
|
73
|
-
fill: "blue",
|
|
74
|
-
shape: "dot",
|
|
75
|
-
text: "Flow size: " + bodySize
|
|
76
|
-
})
|
|
77
|
-
}, 450);
|
|
89
|
+
var access_token = JSON.parse(res.body).access_token;
|
|
78
90
|
|
|
79
|
-
|
|
91
|
+
getFlows({
|
|
92
|
+
"Authorization": "Bearer " + access_token
|
|
93
|
+
}, module.got);
|
|
94
|
+
|
|
95
|
+
}).catch((err) => {
|
|
80
96
|
node.status({fill:"red",shape:"dot",text:"Failed"});
|
|
81
|
-
node.error(err)
|
|
97
|
+
node.error( err );
|
|
82
98
|
});
|
|
83
|
-
}).catch((err) => {
|
|
84
|
-
node.status({fill:"red",shape:"dot",text:"Failed"});
|
|
85
|
-
node.error( err );
|
|
86
99
|
});
|
|
87
100
|
}
|
|
88
101
|
})
|
|
@@ -93,36 +106,12 @@ module.exports = function(RED) {
|
|
|
93
106
|
* Authentication free zone...
|
|
94
107
|
*/
|
|
95
108
|
node.status({fill:"blue",shape:"dot",text:"Requesting flows"});
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
{headers: {"Node-RED-API-Version": cfg.flowVersion}}
|
|
99
|
-
).then( res => {
|
|
100
|
-
if ( res.statusCode == 200 ) {
|
|
101
|
-
var bodySize = res.body.length;
|
|
102
|
-
|
|
103
|
-
send( {
|
|
104
|
-
...msg,
|
|
105
|
-
payload: res.body
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
node.status({fill:"green",shape:"dot",text:"Good"});
|
|
109
|
-
setTimeout( function() {
|
|
110
|
-
node.status({
|
|
111
|
-
fill: "blue",
|
|
112
|
-
shape: "dot",
|
|
113
|
-
text: "Flow size: " + bodySize
|
|
114
|
-
})
|
|
115
|
-
}, 450);
|
|
116
|
-
} else {
|
|
117
|
-
node.error( res );
|
|
118
|
-
node.status({fill:"red",shape:"dot",text:"Failed"});
|
|
119
|
-
}
|
|
120
|
-
}).catch( err => {
|
|
121
|
-
node.status({fill:"red",shape:"dot",text:"Failed"});
|
|
122
|
-
node.error(err)
|
|
109
|
+
import('got').then( (module) => {
|
|
110
|
+
getFlows({}, module.got);
|
|
123
111
|
});
|
|
124
112
|
}
|
|
125
113
|
});
|
|
126
114
|
}
|
|
115
|
+
|
|
127
116
|
RED.nodes.registerType("GetFlows", GetFlowsFunctionality);
|
|
128
117
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gregoriusrippenstein/node-red-contrib-introspection",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.9",
|
|
4
|
+
"dependencies": {
|
|
5
|
+
"got": "latest"
|
|
6
|
+
},
|
|
4
7
|
"keywords": [
|
|
5
8
|
"node-red"
|
|
6
9
|
],
|
|
@@ -8,7 +11,7 @@
|
|
|
8
11
|
"license": "SEE LICENSE IN https://github.com/gorenje/node-red-contrib-introspection/blob/main/LICENSE",
|
|
9
12
|
"author": "Gerrit Riessen <nodered@spreads-the.love> (https://spread-the.love)",
|
|
10
13
|
"engines": {
|
|
11
|
-
"node": ">=
|
|
14
|
+
"node": ">=16"
|
|
12
15
|
},
|
|
13
16
|
"node-red": {
|
|
14
17
|
"version": ">=2.0.0",
|