Browse Source

Ensure relays/bridges are always an array

pull/52/head
Luke Childs 7 years ago
parent
commit
d39886c871
  1. 28
      lib/tor.js

28
lib/tor.js

@ -14,27 +14,25 @@ module.exports = {
return onionoo
.details(query)
.then(response => {
const details = response.body;
if (details.relays) {
details.relays.forEach(setNodeType('relay'));
}
if (details.bridges) {
details.bridges.forEach(setNodeType('bridge'));
}
return details.relays.concat(details.bridges);
const relays = response.body.relays || [];
const bridges = response.body.bridges || [];
relays.forEach(setNodeType('relay'));
bridges.forEach(setNodeType('bridge'));
return relays.concat(bridges);
});
},
node: id => {
return onionoo
.details({ lookup: id })
.then(response => {
const details = response.body;
if (details.relays && details.relays[0]) {
details.relays[0].type = 'relay';
return details.relays[0];
} else if (details.bridges && details.bridges[0]) {
details.bridges[0].type = 'bridge';
return details.bridges[0];
const relays = response.body.relays || [];
const bridges = response.body.bridges || [];
if (relays[0]) {
relays[0].type = 'relay';
return relays[0];
} else if (bridges[0]) {
bridges[0].type = 'bridge';
return bridges[0];
}
});
},

Loading…
Cancel
Save