diff options
Diffstat (limited to 'templates/index.html')
| -rw-r--r-- | templates/index.html | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/templates/index.html b/templates/index.html index 220c8c9..97f5eca 100644 --- a/templates/index.html +++ b/templates/index.html @@ -5,6 +5,7 @@ <title>box</title> <script> function upload() { + token = document.getElementById("token").value f = document.getElementById("file").files[0]; const xhr = new XMLHttpRequest(); xhr.upload.addEventListener("progress", (e) => { @@ -13,20 +14,31 @@ perc = Math.floor(ratio * 100); p.innerHTML = perc + "%"; }); + xhr.onreadystatechange = () => { + if (xhr.readyState === 4) { + if (xhr.status != 200) { + if (xhr.status != 0) { + document.getElementById("progress").innerHTML = "Error: " + xhr.status + " " + xhr.statusText; + } else { + document.getElementById("progress").innerHTML = "Error: unknown"; + } + } + } + } xhr.open("POST", "/" + f.name, true); + xhr.setRequestHeader("X-Upload-Token", token) xhr.send(f) - /*const response = await fetch("/" + name, { - method: "POST", - body: f, - });*/ } </script> </head> <body> <h1>Box</h1> <pre>Server for uploading files. Use the form here or send a POST request to /[filename] with the content of the file in the body.</pre> + {{ if ne . "" }} + <input type="text" id="token"/> + {{end}} <input type="file" id="file"/><br/><br/> - <button type="button" onclick="upload()">Upload</button><br/> + <button type="button" onclick="upload()">Upload</button> <span id="progress"></span> </body> </html> |
