diff options
Diffstat (limited to '')
-rw-r--r-- | site/tracker.hamlet | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/site/tracker.hamlet b/site/tracker.hamlet index 5877c5d..2cc05e4 100644 --- a/site/tracker.hamlet +++ b/site/tracker.hamlet @@ -1,7 +1,7 @@ <h1>_{MsgOBU} <section> - <h2>Blub + <h2>Tracker <strong>Token:</strong> <span id="token"> <section> <h2>Status @@ -116,21 +116,31 @@ async function main() { initGeopos(); - token = await (await fetch("/api/tracker/register/", { - method: "POST", - body: JSON.stringify({agent: "tracktrain-website"}), - headers: {"Content-Type": "application/json"} - })).json(); + let urlparams = new URLSearchParams(window.location.search); - if (token.error) { - alert("could not obtain token: \n" + token.msg); - setStatus("_{MsgTokenFailed}"); - } else { - console.log("got token"); + token = urlparams.get("token"); + + if (token === null) { + token = await (await fetch("/api/tracker/register/", { + method: "POST", + body: JSON.stringify({agent: "tracktrain-website"}), + headers: {"Content-Type": "application/json"} + })).json(); + + if (token.error) { + alert("could not obtain token: \n" + token.msg); + setStatus("_{MsgTokenFailed}"); + } else { + console.log("got token"); + window.location.search = `?token=${token}`; + } + } - document.getElementById("token").innerText = token; + console.log(token) - openWebsocket(); + if (token !== null) { + document.getElementById("token").innerText = token; + openWebsocket(); } } |