From 5092292217a2554ebc9c20294b1ee5a694d05b2f Mon Sep 17 00:00:00 2001 From: John MacFarlane <jgm@berkeley.edu> Date: Thu, 18 Aug 2022 21:57:00 -0700 Subject: [PATCH] trypandoc: more improvements. --- trypandoc/index.html | 2 +- trypandoc/trypandoc.js | 27 ++++++++++++++------------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/trypandoc/index.html b/trypandoc/index.html index 33006f4f8..2e23f58f6 100644 --- a/trypandoc/index.html +++ b/trypandoc/index.html @@ -175,7 +175,7 @@ <p class="version">pandoc version <span id="version"></span></p> </footer> -<script src="trypandoc.js?202208181818"></script> +<script src="trypandoc.js?202208182155"></script> </body> </html> diff --git a/trypandoc/trypandoc.js b/trypandoc/trypandoc.js index 612ed5ac8..d97062b37 100644 --- a/trypandoc/trypandoc.js +++ b/trypandoc/trypandoc.js @@ -52,7 +52,7 @@ function paramsFromURL() { } function handleErrors(response) { - if (response.status == 503) { + if (response.status == 503 || response.status == 500) { throw Error("Conversion timed out.") } else if (!response.ok) { throw Error(response.statusText); @@ -70,16 +70,6 @@ function convert() { citeproc: citeproc }; if (text && text != "") { - fetch("/cgi-bin/pandoc-server.cgi/version") - .then(handleErrors) - .catch(error => - document.getElementById("results").textContent = error ) - .then(response => response.text()) - .then(restext => - document.getElementById("version").textContent = restext - ); - - // console.log(JSON.stringify(params)); let commandString = "pandoc" + " --from " + from + " --to " + to + (standalone ? " --standalone" : "") @@ -90,6 +80,7 @@ function convert() { headers: {"Content-Type": "application/json"}, body: JSON.stringify(params) }) + .then(handleErrors) .then(response => response.text()) .then(restext => { let binary = binaryFormats[to]; @@ -102,7 +93,11 @@ function convert() { document.getElementById("results").textContent = restext; } document.getElementById("permalink").href = permalink(); - }); + }) + .catch(error => { + document.getElementById("results").textContent = error; + } + ); }; } @@ -137,7 +132,6 @@ function convert() { let inputtext = document.getElementById("text"); reader.onloadend = () => { // Use a regex to remove data url part - console.log(mimetype); if (binary) { const base64String = reader.result .replace('data:', '') @@ -154,6 +148,13 @@ function convert() { } }); + fetch("/cgi-bin/pandoc-server.cgi/version") + .then(handleErrors) + .then(response => response.text()) + .then(restext => + document.getElementById("version").textContent = restext + ); + convert(); })();