diff options
| author | Julian Hurst <julian.hurst@digdash.com> | 2025-01-23 11:04:43 +0100 |
|---|---|---|
| committer | Julian Hurst <julian.hurst@digdash.com> | 2025-01-23 11:04:43 +0100 |
| commit | 70cf829b8258cec241dceeb9a02abee626935828 (patch) | |
| tree | 84cfc962a548f6c697bc5b97ae31d12c7ef82e22 /templates | |
| parent | 6037a7e762a2d5015700b96b583a9ecbde9be263 (diff) | |
| download | box-70cf829b8258cec241dceeb9a02abee626935828.tar.gz | |
Support token, host and port flags
Diffstat (limited to 'templates')
| -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> |
