summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--site/index.html48
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)]
+ )
+ ]);
}
}
}