From daabb1665e4a8fc60f234ee86e2e6f2f62ec92c5 Mon Sep 17 00:00:00 2001 From: ztimson Date: Mon, 22 Jun 2026 00:20:37 -0400 Subject: [PATCH] fixing markers --- server/airtraffic.mjs | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/server/airtraffic.mjs b/server/airtraffic.mjs index 1713776..2a43020 100644 --- a/server/airtraffic.mjs +++ b/server/airtraffic.mjs @@ -12,23 +12,16 @@ export async function getShapes() { return JSON.parse(await readFile(SHAPES_PATH, 'utf8')) } - 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', { + headers: { 'User-Agent': 'Mozilla/5.0' } + }) const text = await r.text() - // Rip out just the `let shapes = { ... }` block by finding the matching closing brace - const start = text.indexOf('let shapes = {') - if (start === -1) throw new Error('Could not find shapes definition in markers.js') + let shapes = {} + eval(text.replace('let shapes', 'shapes') + '; shapes = shapes;') - let depth = 0, end = -1 - for (let i = start + 'let shapes = '.length; i < text.length; i++) { - if (text[i] === '{') depth++ - else if (text[i] === '}') { depth--; if (depth === 0) { end = i + 1; break } } - } - - 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)}`)() + const fn = new Function(`${text.replace('let shapes', 'var shapes')}; return shapes;`) + shapes = fn() await writeFile(SHAPES_PATH, JSON.stringify(shapes)) return shapes