Skip to content

Commit

Permalink
fix #78 clone msg to prevent modification on error
Browse files Browse the repository at this point in the history
  • Loading branch information
mblackstock committed Dec 19, 2020
1 parent 329ff9c commit a13dd87
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions influxdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,10 @@ module.exports = function (RED) {
// array of arrays
if (_.isArray(msg.payload[0]) && msg.payload[0].length > 0) {
msg.payload.forEach(function (nodeRedPoint) {
let fields = _.clone(nodeRedPoint[0])
point = {
measurement: measurement,
fields: nodeRedPoint[0],
fields,
tags: nodeRedPoint[1]
}
setFieldIntegers(point.fields)
Expand All @@ -278,9 +279,10 @@ module.exports = function (RED) {
});
} else {
// array of non-arrays, assume one point with both fields and tags
let fields = _.clone(msg.payload[0])
point = {
measurement: measurement,
fields: msg.payload[0],
fields,
tags: msg.payload[1]
};
setFieldIntegers(point.fields)
Expand All @@ -292,11 +294,16 @@ module.exports = function (RED) {
}
} else {
if (_.isPlainObject(msg.payload)) {
let fields = _.clone(msg.payload)
point = {
measurement: measurement,
fields: msg.payload
fields,
};
setFieldIntegers(point.fields)
if (point.fields.time) {
point.timestamp = point.fields.time;
delete point.fields.time;
}
} else {
// just a value
point = {
Expand All @@ -305,10 +312,6 @@ module.exports = function (RED) {
};
setFieldIntegers(point.fields)
}
if (point.fields.time) {
point.timestamp = point.fields.time;
delete point.fields.time;
}
points.push(point);
}

Expand Down

0 comments on commit a13dd87

Please sign in to comment.