main: support multiple data sources
This commit is contained in:
parent
5da5623bf1
commit
5708b63873
|
@ -46,9 +46,9 @@ This will generate `build/` containing all required files.
|
|||
|
||||
Copy `config.json.example` to `build/config.json` and change it to match your community.
|
||||
|
||||
## dataPath (string)
|
||||
## dataPath (string/array)
|
||||
|
||||
`dataPath` must point to the address of a [HopGlass Server](https://github.com/plumpudding/hopglass-server).
|
||||
`dataPath` can be either a string containing the address of a [HopGlass Server](https://github.com/plumpudding/hopglass-server) or an array containing multiple addresses.
|
||||
Don't forget the trailing slash!
|
||||
Also, proxying the data through a webserver will allow GZip and thus will greatly reduce bandwidth consumption.
|
||||
It may help with firewall problems too.
|
||||
|
|
50
lib/main.js
50
lib/main.js
|
@ -2,12 +2,39 @@ define(["moment", "router", "leaflet", "gui", "numeral"],
|
|||
function (moment, Router, L, GUI, numeral) {
|
||||
return function (config) {
|
||||
function handleData(data) {
|
||||
var dataNodes = data[0]
|
||||
var dataGraph = data[1]
|
||||
var dataNodes = {}
|
||||
dataNodes.nodes = []
|
||||
var dataGraph = {}
|
||||
dataGraph.batadv = {}
|
||||
dataGraph.batadv.nodes = []
|
||||
dataGraph.batadv.links = []
|
||||
|
||||
if (dataNodes.version !== 2 || dataGraph.version !== 1) {
|
||||
var err = "Unsupported nodes or graph version: " + dataNodes.version + " " + dataGraph.version
|
||||
throw err
|
||||
|
||||
function rearrangeLinks(d) {
|
||||
d.source += dataGraph.batadv.nodes.length
|
||||
d.target += dataGraph.batadv.nodes.length
|
||||
}
|
||||
|
||||
for (var i = 0; i < data.length; ++i) {
|
||||
var vererr
|
||||
if(i % 2)
|
||||
if (data[i].version !== 1) {
|
||||
vererr = "Unsupported graph version: " + data[i].version
|
||||
console.log(vererr) //silent fail
|
||||
} else {
|
||||
data[i].batadv.links.forEach(rearrangeLinks)
|
||||
dataGraph.batadv.nodes = dataGraph.batadv.nodes.concat(data[i].batadv.nodes)
|
||||
dataGraph.batadv.links = dataGraph.batadv.links.concat(data[i].batadv.links)
|
||||
dataGraph.timestamp = data[i].timestamp
|
||||
}
|
||||
else
|
||||
if (data[i].version !== 2) {
|
||||
vererr = "Unsupported nodes version: " + data[i].version
|
||||
console.log(vererr) //silent fail
|
||||
} else {
|
||||
dataNodes.nodes = dataNodes.nodes.concat(data[i].nodes)
|
||||
dataNodes.timestamp = data[i].timestamp
|
||||
}
|
||||
}
|
||||
|
||||
var nodes = dataNodes.nodes.filter( function (d) {
|
||||
|
@ -96,9 +123,16 @@ function (moment, Router, L, GUI, numeral) {
|
|||
|
||||
var router = new Router()
|
||||
|
||||
var urls = [ config.dataPath + "nodes.json",
|
||||
config.dataPath + "graph.json"
|
||||
]
|
||||
var urls = []
|
||||
|
||||
if (typeof config.dataPath === "string" || config.dataPath instanceof String)
|
||||
config.dataPath = [config.dataPath]
|
||||
|
||||
for (var i in config.dataPath) {
|
||||
urls.push(config.dataPath[i] + "nodes.json")
|
||||
urls.push(config.dataPath[i] + "graph.json")
|
||||
}
|
||||
|
||||
function update() {
|
||||
return Promise.all(urls.map(getJSON))
|
||||
.then(handleData)
|
||||
|
|
Loading…
Reference in a new issue