Files
Kakubovna/app/forms/download.html
Dzejkobik007 a8aa121d6f update
2023-06-09 07:09:47 +02:00

97 lines
3.6 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Kakubovna: Download</title>
<link rel="stylesheet" href="/css/style.css">
<link href="https://fonts.googleapis.com/css2?family=Geologica:wght@800&display=swap" rel="stylesheet">
</head>
<body>
<div class="flex-container">
<div id="code-view" class="container vertical" style="display:none">
<input id="code" type="text" placeholder="Enter code">
<button onclick="checkUpload()">Submit</button>
<p id="status"></p>
</div>
<div id="file-view" class="container vertical file-view" style="display:none">
</div>
<div id="admin-file-view" class="container vertical" style="display:none">
<input id="code" type="text" placeholder="Enter code">
<button onclick="checkUpload()">Submit</button>
<p id="status"></p>
</div>
</div>
<script src="/js/script.js"></script>
<script>
var hash = "";
var adminHash = "";
handleUrl();
function handleUrl() {
console.log(document.location.pathname.split("/", 4));
path = document.location.pathname.split("/", 4)
if(path[2] !== undefined && path[2].length > 10 && path[2] === path[2].toUpperCase()) {
hash = path[2];
loadFiles();
document.getElementById("file-view").style = "";
if(path[3] !== undefined && path[3].length == 10 && path[3] === path[3].toUpperCase()) {
adminHash = path[3];
document.getElementById("admin-file-view").style = "";
}
} else {
document.getElementById("code-view").style = "";
}
}
codeInput = document.getElementById("code");
statusText = document.getElementById("status");
function checkUpload() {
if (!(codeInput.value.length > 10 && codeInput.value === codeInput.value.toUpperCase())) {
statusText.innerHTML = 'Wrong Code';
return;
}
fetch('/api/download/' + codeInput.value)
.then(
response => response.json()
).then(jsonResponse => {
console.log(jsonResponse);
if (jsonResponse.code == 404) {
statusText.innerHTML = 'Not Found';
} else if (jsonResponse.code == 200) {
statusText.innerHTML = 'Found';
window.location.href = document.location.protocol + "//" + document.location.host + "/download/" + codeInput.value
} else {
statusText.innerHTML = 'Error';
}
});
};
function loadFiles() {
var fileview = document.getElementById("file-view");
fetch('/api/download/' + hash)
.then(
response => response.json()
).then(jsonResponse => {
console.log(jsonResponse);
if (jsonResponse.code == 200) {
table = "<table class=\"file-table\"><tbody class=\"files\">";
var i = 0
jsonResponse.result.files.forEach(file => {
table += "<tr id=\"file\"><td id=\"name\"><p title=\""+file.filename+"\">"+shortString(file.filename, 20)+"</p></td><td id=\"actions\"><div class=\"action-box\"><img id=\"img-download\" src=\"/img/cloud-download-outline-white.svg\" alt=\"Download\"><a target=\”_blank\” href='"+document.location.protocol+"//"+document.location.host+"/download/"+hash+"/index/"+i+"'></a></div></td></tr>";
i++;
});
table += "</tbody></table>";
fileview.innerHTML = table;
} else {
fileview.innerHTML = "<h1>Not Found</h1>";
}
});
}
</script>
</body>
</html>