Simple file upload and browsing

This commit is contained in:
kamkow1
2025-06-21 02:05:25 +02:00
parent c5f009654c
commit 622b98f40a
7 changed files with 496 additions and 7 deletions

18
tmpls/browse.html Normal file
View File

@ -0,0 +1,18 @@
<html>
<head>
<title>Lair Tremporary Storage</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="/etc/simple.css" />
</head>
<body>
<table>
{{range .}}
<tr>
<td><a href="/store/{{.FileName}}">{{.ReadableName}}</a></td>
<td><span>{{.Perm}}</span></td>
<td><span>{{.Modtime}}</span></td>
</tr>
{{end}}
</table>
</body>
</html>

View File

@ -7,10 +7,70 @@
<body>
<h1>Lair Tremporary Storage</h1>
<section>
<h2>Welcome</h2>
<p>
Welcome to The Lair's temporary storage service. Use this service to transport files via
a temporary remote storage. ONLY WHITELISTED IPs CAN UPLOAD!!
a temporary remote storage. <br />
ONLY WHITELISTED USERS can upload! For access, reach out to <a href="mailto:kamkow256@gmail.com">me</a>.<br />
Only 30PLN / 12MON.
</p>
</section>
<section>
<h2>Upload</h2>
<p>
<form id="upload-form" method="POST" enctype="multipart/form-data">
<input type="file" name="myfile" id="myfile" required />
<input type="text" name="user" id="user" required />
<input type="password" name="pass", id="pass" required />
<input type="submit" value="Upload" />
</form>
</p>
</section>
<section>
<h2>Browse</h2>
<p>
Browse the files <a href="/store">here</a>
</p>
</section>
<script>
let upload_form = document.getElementById("upload-form");
upload_form.addEventListener("submit", async function (event) {
event.preventDefault();
const file_input = document.getElementById("myfile");
const file = file_input.files[0];
if (!file) {
alert("Select a file");
return;
}
const form_data = new FormData();
form_data.append("myfile", file);
const user = document.getElementById("user").value;
const pass = document.getElementById("pass").value;
console.log(form_data);
console.log(user, pass);
const auth = "Basic " + btoa(user + ":" + pass);
try {
const host = window.location.origin;
const res = await fetch(host + "/upload", {
method: "POST",
headers: {
"Authorization": auth,
},
body: form_data,
});
const text = await res.text();
alert(text);
} catch (err) {
alert("Error: " + err);
}
});
</script>
</body>
</html>