sxbin/templates/index.html

337 lines
10 KiB
HTML
Raw Normal View History

2024-09-08 13:13:50 +02:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>aCloud</title>
2024-09-08 13:13:50 +02:00
<style>
body {
font-family: Arial, sans-serif;
background-color: #121212;
color: #e0e0e0;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.container {
background: #1e1e1e;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
padding: 20px;
width: 400px;
text-align: center;
}
h1 {
margin-bottom: 20px;
color: #f5f5f5;
}
.upload-options {
display: flex;
justify-content: center;
margin-bottom: 20px;
}
.upload-options button {
background-color: #007bff;
color: #fff;
border: none;
border-radius: 4px;
padding: 10px 20px;
margin: 0 10px;
cursor: pointer;
}
.upload-options button.active {
background-color: #0056b3;
}
.upload-form {
display: none;
}
.upload-form.active {
display: block;
}
textarea, input[type="file"], input[type="text"] {
width: calc(100% - 20px);
margin-top: 10px;
padding: 10px;
border-radius: 4px;
border: 1px solid #333;
box-sizing: border-box;
background-color: #2e2e2e;
color: #e0e0e0;
}
button[type="button"] {
background-color: #28a745;
color: #fff;
border: none;
border-radius: 4px;
padding: 10px 20px;
margin-top: 10px;
cursor: pointer;
}
.result {
margin-top: 20px;
color: #f5f5f5;
}
2024-09-08 13:14:40 +02:00
.footer {
background-color: #2c2f33;
color: #99aab5;
padding: 10px 0;
position: fixed;
bottom: 0;
width: 100%;
text-align: center;
font-size: 14px;
}
2024-09-08 13:14:40 +02:00
.footer a {
color: #61afef;
text-decoration: none;
}
2024-09-08 13:14:40 +02:00
.footer a:hover {
text-decoration: underline;
}
2024-09-08 13:14:40 +02:00
.footer .container {
max-width: 1200px;
margin: 0 auto;
padding: 0 15px;
}
2024-09-08 13:14:40 +02:00
.typewriter-container {
font-size: 23px;
text-align: center;
white-space: nowrap;
overflow: hidden;
position: relative;
}
.typewriter-text {
display: inline-block;
white-space: nowrap;
}
.cursor {
display: inline-block;
width: 10px;
height: 1em;
background-color: #ff69b4;
animation: blink 0.7s step-end infinite;
position: absolute;
right: 0;
bottom: 0;
}
@keyframes blink {
50% {
background-color: transparent;
}
}
2024-09-08 13:13:50 +02:00
</style>
</head>
<body>
2024-09-08 13:13:50 +02:00
<div class="container">
<div class="typewriter-container">
<span id="typewriter-text" class="typewriter-text"></span><span id="cursor" class="cursor"></span>
</div>
</br>
</br>
2024-09-08 13:13:50 +02:00
<div class="upload-options">
<button id="textUploadBtn" onclick="showForm('text')">Upload Text</button>
<button id="fileUploadBtn" onclick="showForm('file')">Upload File</button>
<button id="folderUploadBtn" onclick="showForm('folder')">Upload Folder</button>
2024-09-08 13:13:50 +02:00
<button id="urlShortenerBtn" onclick="showForm('url')">Shorten URL</button>
</div>
<div id="uploadFormContainer">
<div id="textForm" class="upload-form">
<h2>Upload Text</h2>
<form>
<textarea name="content" rows="4" placeholder="Enter text here..."></textarea>
<button type="button" onclick="uploadText()">Upload Text</button>
</form>
<div id="textResult" class="result"></div>
</div>
<div id="fileForm" class="upload-form">
<h2>Upload File</h2>
<form enctype="multipart/form-data">
<input type="file" name="file" />
<button type="button" onclick="uploadFile()">Upload File</button>
</form>
<div id="fileResult" class="result"></div>
</div>
<div id="folderForm" class="upload-form">
<h2>Upload Folder</h2>
<form enctype="multipart/form-data">
<input type="file" name="file" webkitdirectory directory />
<button type="button" onclick="uploadFolder()">Upload Folder</button>
</form>
<div id="folderResult" class="result"></div>
</div>
2024-09-08 13:13:50 +02:00
<div id="urlForm" class="upload-form">
<h2>Shorten URL</h2>
<form>
<input type="text" name="url" placeholder="Enter URL here..." />
<button type="button" onclick="shortenUrl()">Shorten URL</button>
</form>
<div id="urlResult" class="result"></div>
</div>
</div>
</div>
<script>
document.addEventListener("DOMContentLoaded", function() {
const message1 = "Welcome to aCloud.";
const message2 = "\n A simple toolbox for file uploading,\n URL shortening and pastebin.";
const typewriterTextElement = document.getElementById('typewriter-text');
const cursorElement = document.getElementById('cursor');
const typingSpeed = 70;
function typeMessage(message, callback) {
let index = 0;
function typeCharacter() {
if (index < message.length) {
if (message[index] === '\n') {
typewriterTextElement.innerHTML += '<br>';
} else {
typewriterTextElement.innerHTML += message[index];
}
index++;
updateCursorPosition();
setTimeout(typeCharacter, typingSpeed);
} else if (callback) {
setTimeout(callback, typingSpeed);
}
}
typeCharacter();
}
function updateCursorPosition() {
const textRect = typewriterTextElement.getBoundingClientRect();
cursorElement.style.left = (textRect.width + textRect.left - cursorElement.offsetWidth) + 'px';
}
typeMessage(message1, function() {
typeMessage(message2);
});
});;
document.getElementById('uploadForm').onsubmit = function(e) {
e.preventDefault();
var formData = new FormData(this);
var xhr = new XMLHttpRequest();
xhr.open('POST', '/upload/file', true);
xhr.upload.onprogress = function(e) {
if (e.lengthComputable) {
var percentComplete = (e.loaded / e.total) * 100;
document.getElementById('progressBar').style.display = 'block';
document.getElementById('progressBar').value = percentComplete;
}
};
xhr.onload = function() {
if (xhr.status === 200) {
alert('Upload complete!');
document.getElementById('progressBar').style.display = 'none';
} else {
alert('Upload failed.');
}
};
xhr.send(formData);
};
2024-09-08 13:13:50 +02:00
function showForm(type) {
document.querySelectorAll('.upload-form').forEach(form => {
form.classList.remove('active');
});
document.getElementById(type + 'Form').classList.add('active');
2024-09-08 13:13:50 +02:00
}
function uploadText() {
const content = document.querySelector('#textForm textarea').value;
2024-09-08 13:13:50 +02:00
fetch('/upload/pastebin', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: new URLSearchParams({ content }),
2024-09-08 13:13:50 +02:00
})
.then(response => response.json())
.then(data => {
document.getElementById('textResult').innerHTML = `Text uploaded. Access it <a href="/${data.vanity}">here</a>.`;
2024-09-08 13:13:50 +02:00
});
}
function uploadFile() {
const formData = new FormData();
formData.append('file', document.querySelector('#fileForm input[type="file"]').files[0]);
2024-09-08 13:13:50 +02:00
fetch('/upload/file', {
method: 'POST',
body: formData,
2024-09-08 13:13:50 +02:00
})
.then(response => response.json())
.then(data => {
document.getElementById('fileResult').innerHTML = `File uploaded. Download it <a href="/download/${data.vanity}">here</a>.`;
2024-09-08 13:13:50 +02:00
});
}
function uploadFolder() {
const files = document.querySelector('#folderForm input[type="file"]').files;
if (files.length === 0) {
alert('Please select a folder.');
return;
}
2024-09-08 13:13:50 +02:00
const formData = new FormData();
for (const file of files) {
formData.append('file', file);
}
fetch('/upload/folder', {
method: 'POST',
body: formData,
})
.then(response => response.json())
.then(data => {
document.getElementById('folderResult').innerHTML = `Folder uploaded. View its contents <a href="/${data.vanity}">here</a>.`;
});
}
function shortenUrl() {
const url = document.querySelector('#urlForm input[name="url"]').value;
2024-09-08 13:13:50 +02:00
fetch('/shorten', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: new URLSearchParams({ url }),
2024-09-08 13:13:50 +02:00
})
.then(response => response.json())
.then(data => {
document.getElementById('urlResult').innerHTML = `URL shortened. Access it <a href="/${data.vanity}">here</a>.`;
2024-09-08 13:13:50 +02:00
});
}
</script>
</body>
<footer class="footer">
<div class="container">
<p class="footer-text">Source code available on:
<a href="https://github.com/realcgcristi/order" target="_blank">GitHub (not up-to-date)</a> |
<a href="https://git.spitkov.hu/cgcristi/aCloud" target="_blank">Spitkov's Git (main)</a>
2024-09-08 13:13:50 +02:00
</p>
</div>
</footer>
</html>