Fixed marker url
This commit is contained in:
@@ -15,16 +15,22 @@ export async function getShapes() {
|
|||||||
const r = await fetch('https://raw.githubusercontent.com/wiedehopf/tar1090/refs/heads/master/html/markers.js')
|
const r = await fetch('https://raw.githubusercontent.com/wiedehopf/tar1090/refs/heads/master/html/markers.js')
|
||||||
const text = await r.text()
|
const text = await r.text()
|
||||||
|
|
||||||
// tar1090 exposes a var with all the shape definitions
|
// Rip out just the `let shapes = { ... }` block by finding the matching closing brace
|
||||||
let shapes = {}
|
const start = text.indexOf('let shapes = {')
|
||||||
try {
|
if (start === -1) throw new Error('Could not find shapes definition in markers.js')
|
||||||
const match = text.match(/let\s+shapes\s*=\s*(\{[\s\S]*?\n\})/);
|
|
||||||
if (match) shapes = JSON.parse(match[1])
|
let depth = 0, end = -1
|
||||||
} catch (e) {
|
for (let i = start + 'let shapes = '.length; i < text.length; i++) {
|
||||||
console.error('Failed to parse tar1090 shapes:', e)
|
if (text[i] === '{') depth++
|
||||||
|
else if (text[i] === '}') { depth--; if (depth === 0) { end = i + 1; break } }
|
||||||
}
|
}
|
||||||
|
|
||||||
writeFile(SHAPES_PATH, JSON.stringify(shapes), () => {})
|
if (end === -1) throw new Error('Could not find end of shapes definition')
|
||||||
|
|
||||||
|
// Use Function to eval the JS object safely (avoids JSON.parse issues with unquoted keys, comments etc)
|
||||||
|
const shapes = new Function(`return ${text.slice(start + 'let shapes = '.length, end)}`)()
|
||||||
|
|
||||||
|
await writeFile(SHAPES_PATH, JSON.stringify(shapes))
|
||||||
return shapes
|
return shapes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user