-
Notifications
You must be signed in to change notification settings - Fork 3
/
data.js
81 lines (77 loc) · 2.52 KB
/
data.js
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
var getListeners = function (callback) {
var listeners = [];
var file = './data/listeners.inc';
fs = require('fs');
fs.readFile(file, 'utf8', function (err, data) {
var items = data.split('\n');
items.forEach(function (line) {
line = line.replace(/\n$/, '').trim();
var parts = line.split('|');
if (parts.length > 1 && line[0] != ';') {
if (typeof parts[3] != 'undefined' && parts[3].indexOf(",") != -1) {
senderList = parts[3].split(',');
} else {
senderList = [parts[3]];
}
var listener = {
name: parts[0],
type: parts[1],
url: parts[2],
senders: senderList,
};
if (listener.type == 'AMQP') {
var amqpParts = parts[2].split(':');
listener.server = amqpParts[0];
listener.queue = amqpParts[1];
listener.key = amqpParts[2];
listener.exchange = amqpParts[3];
}
listeners.push(listener);
}
});
if (err) {
return console.log(err);
}
callback(listeners);
});
//return listeners;
};
var getSenders = function (callback) {
var senders = [];
var file = './data/senders.inc';
//console.log('parse FIle');
fs = require('fs');
//console.log(fs);
fs.readFile(file, 'utf8', function (err, data) {
var items = data.split('\n');
items.forEach(function (line) {
line = line.replace(/\n$/, '').trim();
var parts = line.split('|');
if (parts.length > 0 && line[0] != ';') {
var sender = {
name: parts[0],
type: parts[1],
url: parts[2],
dataType: parts[3],
};
if (sender.type == 'AMQP') {
var amqpParts = parts[2].split(':');
sender.queue = amqpParts[0];
sender.key = amqpParts[1];
sender.exchange = amqpParts[2];
}
senders.push(sender);
}
});
callback(senders);
if (err) {
return console.log(err);
}
});
//console.log(senders);
//return senders;
};
module.exports = {
getListeners: getListeners,
getSenders: getSenders
};