diff options
author | stuebinm | 2021-04-05 00:37:53 +0200 |
---|---|---|
committer | stuebinm | 2021-04-05 00:42:46 +0200 |
commit | fbbc5ad93188e71e337ad6d2587b284be4e96756 (patch) | |
tree | 4298ae8501ffe9ec74940293cfea6c56d86ee0c6 /site/index.html | |
parent | 564ab9056268e05621ceb4878ba3b3683abeaf10 (diff) |
load survey from (and submit result to) path given as fragment
syntax: http(s)://domain.tld/path/to/file/index.html#[upload url]
The upload url may be relative to the site's position, or absolute.
Survey results will be POSTed to [upload path]/upload.
Diffstat (limited to 'site/index.html')
-rw-r--r-- | site/index.html | 48 |
1 files changed, 30 insertions, 18 deletions
diff --git a/site/index.html b/site/index.html index 7fef9e9..1378bdf 100644 --- a/site/index.html +++ b/site/index.html @@ -21,6 +21,7 @@ /// polymorphism which would otherwise be hard to get in javascript. let root = document.getElementById("root"); + let surveyUrl = window.location.hash.slice(1); // appends multiple children to an element. returns the root // element to be composable @@ -151,8 +152,7 @@ { type: 'application/octet-stream' } ); - // TODO! - fetch(`http://localhost:8000/upload`, {method:"POST", body:blobData}) + fetch("/upload", {method:"POST", body:blobData}) .then(response => console.log(response.text())) } @@ -206,27 +206,39 @@ // initialise the web assembly parts of this await init(); const Http = new XMLHttpRequest(); - const url="http://127.0.0.1:8000/pubcrypt.age"; + const url= surveyUrl; Http.open("GET", url); Http.responseType = "arraybuffer"; Http.send(); Http.onreadystatechange = (e) => { - if (Http.readyState == 4 && Http.status == 200) { - let bytearray = new Uint8Array (Http.response); - let string = String.fromCharCode.apply(null, bytearray); - let survey = null; - try { - survey = JSON.parse(string); - } catch (e) { - console.log ("survey appears to be encrypted"); - askPassphrase(bytearray); - } - /// if the survey was unencrypted, start it here. If it - /// was encrypted, we need to wait for user action via - /// a js callback (handled in askPassphrase). - if (survey !== null) { - mkSurvey(survey); + if (Http.readyState == 4) { + if (Http.status == 200) { + let bytearray = new Uint8Array (Http.response); + let string = String.fromCharCode.apply(null, bytearray); + let survey = null; + try { + survey = JSON.parse(string); + } catch (e) { + console.log ("survey appears to be encrypted"); + askPassphrase(bytearray); + } + /// if the survey was unencrypted, start it here. If it + /// was encrypted, we need to wait for user action via + /// a js callback (handled in askPassphrase). + if (survey !== null) { + mkSurvey(survey); + } + // couldn't load survey json, show error message + } else { + appendChildren(root, [ + mkElement("h1", "Error"), + mkElement("p", "Could not load this survey; are you sure that it exists?"), + appendChildren( + mkElement("p","attempted path: "), + [mkElement("tt", surveyUrl)] + ) + ]); } } } |