<!DOCTYPE HTML>
<html>
	<head>
		<meta name="viewport" content="width=device-width, initial-scale=1" />
		<title>Box</title>
		<script>
			function upload() {
				let resourceId = "";
				token = document.getElementById("token");
				if (token == null) {
					token = "";
				} else {
					token = token.value;
				}
				f = document.getElementById("file").files[0];
				const xhr = new XMLHttpRequest();
				xhr.upload.addEventListener("progress", (e) => {
					p = document.getElementById("progress")
					ratio = e.loaded / e.total;
					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";
							}
						} else {
							document.getElementById("progress").innerHTML = "Done: <a href=\"/" + resourceId + "\">" + resourceId + "</a>";
						}
					}
					if (xhr.readyState === xhr.HEADERS_RECEIVED) {
						resourceId = xhr.getResponseHeader("X-Resource-ID");
					}
				}
				xhr.open("POST", "/upload", true);
				xhr.setRequestHeader("X-Token", token);
				ldot = f.name.lastIndexOf(".");
				if (ldot > -1) {
					xhr.setRequestHeader("X-ResourceMeta-Extension", f.name.substring(ldot))
				}
				xhr.send(f)
			}
		</script>
	</head>
	<body>
		<pre>
 _
| |__   _____  __
| '_ \ / _ \ \/ /
| |_) | (_) >  <
|_.__/ \___/_/\_\

Server for uploading files.

Use the form here or send a POST request to /upload with the content of the file in the body.
The request can contain a X-ResourceMeta-Extension header with the desired extension of the file including the dot (i.e. .gif or .flac).
This will improve compatibility when fetching the file.
If a token has been set on the server, pass the token in the request via a X-Token header.

The response will contain a X-Resource-ID header containing the ID of the saved file.
This ID can then be used to get the file by sending a GET request to /[resourceID].

If enabled on the server, the resource can be deleted by sending a DELETE request to /[resourceID].
Again if a token has been set on the server, use a X-Token header when sending the request.</pre>
		{{ if ne . "" }}
			<input type="text" id="token" placeholder="token"/>
		{{end}}
		<input type="file" id="file"/><br/><br/>
		<button type="button" onclick="upload()">Upload</button>
		<span id="progress"></span>
	</body>
</html>
