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 return onionoo
.details(query) .details(query)
.then(response => { .then(response => {
const details = response.body; const relays = response.body.relays || [];
if (details.relays) { const bridges = response.body.bridges || [];
details.relays.forEach(setNodeType('relay')); relays.forEach(setNodeType('relay'));
} bridges.forEach(setNodeType('bridge'));
if (details.bridges) { return relays.concat(bridges);
details.bridges.forEach(setNodeType('bridge'));
}
return details.relays.concat(details.bridges);
}); });
}, },
node: id => { node: id => {
return onionoo return onionoo
.details({ lookup: id }) .details({ lookup: id })
.then(response => { .then(response => {
const details = response.body; const relays = response.body.relays || [];
if (details.relays && details.relays[0]) { const bridges = response.body.bridges || [];
details.relays[0].type = 'relay'; if (relays[0]) {
return details.relays[0]; relays[0].type = 'relay';
} else if (details.bridges && details.bridges[0]) { return relays[0];
details.bridges[0].type = 'bridge'; } else if (bridges[0]) {
return details.bridges[0]; bridges[0].type = 'bridge';
return bridges[0];
} }
}); });
}, },

Loading…
Cancel
Save