node-red-contrib-tak-registration 0.10.0 → 0.11.0

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 CHANGED
@@ -82,5 +82,7 @@ It will produce a well formatted JSON object containing the event. It is returne
82
82
 
83
83
  **msg.topic** is set to the COT type.
84
84
 
85
+ If an event arrives with a *fileshare* link, it will fetch the file and add **msg.filename** and **msg.datapackage** to the output msg. The datapackage will be a buffer.
86
+
85
87
  It can also accept input from a UDP node configured to listen to *multicast* on group 239.2.3.1 port 6969. The JSON object produced contains similar information but formatted/organised slightly differently. (Very annoying).
86
88
  It is returned as **msg.payload.cotEvent**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-tak-registration",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "description": "A Node-RED node to register to TAK and to help wrap files as datapackages to send to TAK",
5
5
  "dependencies": {
6
6
  "@turf/turf": "6.5.0",
package/tak-ingest.html CHANGED
@@ -37,4 +37,7 @@
37
37
  <code>_takgatewaycs</code> and <code>_takgatewayId</code> that can be used
38
38
  as look ups for other messages.</p>
39
39
  <p>It also sets <code>msg.topic</code> to the event type to make switching easier.</p>
40
+ <p>If an event arrives with a <i>fileshare</i> link, it will fetch the file and add
41
+ <code>msg.filename</code> and <code>msg.datapackage</code> to the output msg.
42
+ The datapackage will be a buffer.</p>
40
43
  </script>
package/tak-ingest.js CHANGED
@@ -1,4 +1,5 @@
1
1
  const { XMLParser, XMLBuilder, XMLValidator} = require("fast-xml-parser");
2
+ const axios = require('axios').default;
2
3
  var Long = require('long').Long;
3
4
  var protobuf = require('protobufjs');
4
5
  var path = require('path');
@@ -86,7 +87,26 @@ module.exports = function(RED) {
86
87
  global.set("_takgatewayid", b);
87
88
  }
88
89
  if (msg.payload?.event?.type) { msg.topic = msg.payload?.event?.type; }
89
- node.send(msg);
90
+ if (msg.payload?.event?.detail?.fileshare) {
91
+ msg.filename = msg.payload.event.detail.fileshare.filename;
92
+ axios({
93
+ method: 'get',
94
+ url: msg.payload.event.detail.fileshare.senderUrl,
95
+ headers: { 'Accept': 'application/zip' },
96
+ responseType: 'arraybuffer'
97
+ })
98
+ .then(function (response) {
99
+ msg.datapackage = Buffer.from(response.data);
100
+ node.send(msg);
101
+ })
102
+ .catch(function (error) {
103
+ node.error(error.message, error);
104
+ node.send(msg);
105
+ })
106
+ }
107
+ else {
108
+ node.send(msg);
109
+ }
90
110
  });
91
111
 
92
112
  node.on("close", function() {
@@ -104,7 +104,7 @@ module.exports = function (RED) {
104
104
  node.status({ fill: "green", shape: "dot", text: node.repeat / 1000 + "s - " + node.callsign });
105
105
  return;
106
106
  }
107
- // if it's just a simple filename and payload then make it look like an attachment etc...
107
+ // if it's just a simple filename and buffer payload then make it look like an attachment etc...
108
108
  if (msg.hasOwnProperty("filename") && Buffer.isBuffer(msg.payload) && !msg.hasOwnProperty("attachments")) {
109
109
  msg.attachments = [{
110
110
  filename: msg.filename.split('/').pop(),
@@ -166,7 +166,6 @@ module.exports = function (RED) {
166
166
  cott = cott.replace(/>\s+</g, "><");
167
167
  var hsh = crypto.createHash('md5').update(cott).digest('hex');
168
168
  zip.addFile(hsh+'/'+hsh+'.cot', cott, "Added by Node-RED");
169
-
170
169
  mf += `<Content ignore="false" zipEntry="${hsh+'/'+hsh+'.cot'}"><Parameter name="uid" value="${UUID}"/></Content>\n`;
171
170
  }
172
171
 
@@ -177,10 +176,10 @@ module.exports = function (RED) {
177
176
  zip.writeZip("/tmp/takfile.zip")
178
177
 
179
178
  msg = {
180
- from: node.callsign || msg.from || "Anonymous",
179
+ from: msg.from || node.callsign || "Anonymous",
181
180
  sendTo: msg.sendTo,
182
- lat: node.lat || msg.lat || 0,
183
- lon: node.lon || msg.lon || 0,
181
+ lat: msg.lat || node.lat || 0,
182
+ lon: msg.lon || node.lon || 0,
184
183
  assetfile: fname,
185
184
  len: zipbuff.length,
186
185
  uid: node.uuid,