-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmeta_tagging.js
More file actions
42 lines (34 loc) · 1.38 KB
/
Copy pathmeta_tagging.js
File metadata and controls
42 lines (34 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
MIT License Copyright 2021-2024 - Bitpool Pty Ltd
*/
module.exports = function (RED) {
function apptag(config) {
RED.nodes.createNode(this, config);
var node = this;
this.StreamTags = config.StreamTags;
this.taglib = config.taglib;
this.tagRegisters = config.tagRegisters;
this.streamTagList = config.streamTagList;
node.on('input', function (msg) {
for (let i = 0; i < node.tagRegisters.length; i++) {
let currentTag = node.tagRegisters[i];
let filterArray = currentTag.filter.split(',');
filterArray.forEach(item => {
let msgTopic = msg.topic.toLowerCase();
let itemName = item.toLowerCase().trim();
if (msgTopic.includes(itemName)) {
let existingTags = msg.meta;
if (!existingTags) {
msg.meta = currentTag.tagList;
} else if (!existingTags.includes(currentTag.tagList)) {
msg.meta = existingTags + ", " + currentTag.tagList;
}
}
});
};
node.send(msg);
node.status({ fill: "green", shape: "dot", text: "Tags added to payload" });
});
}
RED.nodes.registerType("metatag", apptag);
}