瀏覽代碼

check nodes and graph version

Nils Schneider 9 年之前
父節點
當前提交
c734975a3b
共有 1 個文件被更改,包括 12 次插入3 次删除
  1. 12 3
      lib/main.js

+ 12 - 3
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)
       })
   }