From c734975a3b43c8fbf627e16a6fab0a8ecc27573c Mon Sep 17 00:00:00 2001 From: Nils Schneider Date: Tue, 7 Apr 2015 21:10:37 +0200 Subject: [PATCH] check nodes and graph version --- lib/main.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index 941b297..c057aea 100644 --- a/lib/main.js +++ b/lib/main.js @@ -2,7 +2,15 @@ define(["config", "moment", "router", "leaflet", "gui", "numeral"], function (config, moment, Router, L, GUI, numeral) { return function () { function handleData(data) { - var nodes = Object.keys(data[0].nodes).map(function (key) { return data[0].nodes[key] }) + var dataNodes = data[0] + var dataGraph = data[1] + + if (dataNodes.version !== 1 || dataGraph.version !== 1) { + var err = "Unsupported nodes or graph version: " + dataNodes.version + " " + dataGraph.version + throw err + } + + var nodes = Object.keys(dataNodes.nodes).map(function (key) { return dataNodes.nodes[key] }) nodes = nodes.filter( function (d) { return "firstseen" in d && "lastseen" in d @@ -19,8 +27,8 @@ function (config, moment, Router, L, GUI, numeral) { var newnodes = limit("firstseen", age, sortByKey("firstseen", nodes).filter(online)) var lostnodes = limit("lastseen", age, sortByKey("lastseen", nodes).filter(offline)) - var graph = data[1].batadv - var graphnodes = data[0].nodes + var graphnodes = dataNodes.nodes + var graph = dataGraph.batadv graph.nodes.forEach( function (d) { if (d.node_id in graphnodes) @@ -108,6 +116,7 @@ function (config, moment, Router, L, GUI, numeral) { }, 60000) }) .catch(function (e) { + document.body.textContent = e console.log(e) }) }