diff --git a/templates/index.html b/templates/index.html index de5dfd7..ff763b5 100644 --- a/templates/index.html +++ b/templates/index.html @@ -5,117 +5,479 @@ aCloud - File Sharing Service
+ + +
@@ -123,7 +485,6 @@
-
@@ -143,14 +504,6 @@
-
-

Upload Folder

-
- - -
-
-

Shorten URL

@@ -199,7 +552,6 @@ } function updateCursorPosition() { - const textRect = typewriterTextElement.getBoundingClientRect(); cursorElement.style.left = (textRect.width + textRect.left - cursorElement.offsetWidth) + 'px'; } @@ -207,9 +559,19 @@ typeMessage(message1, function() { typeMessage(message2); }); - });; + const settingsButton = document.getElementById('settingsButton'); + const settingsMenu = document.getElementById('settingsMenu'); + settingsButton.addEventListener('click', function() { + settingsMenu.style.display = settingsMenu.style.display === 'none' ? 'block' : 'none'; + }); + }); + + function setTheme(theme) { + document.body.className = theme; + } + document.getElementById('uploadForm').onsubmit = function(e) { e.preventDefault(); var formData = new FormData(this); @@ -247,48 +609,45 @@ fetch('/upload/pastebin', { method: 'POST', headers: { - 'Content-Type': 'application/x-www-form-urlencoded', + 'Content-Type': 'application/json', }, - body: new URLSearchParams({ content }), + body: JSON.stringify({ content: content }), }) .then(response => response.json()) .then(data => { - document.getElementById('textResult').innerHTML = `Text uploaded. Access it here.`; + if (data.success) { + const simpleUrl = `${window.location.origin}/${data.vanity}`; + document.getElementById('textResult').innerHTML = `Pastebin created. Access it ${simpleUrl}`; + } else { + document.getElementById('textResult').innerHTML = `Error: ${data.error}`; + } + }) + .catch(error => { + console.error('Error:', error); + document.getElementById('textResult').innerHTML = `An error occurred: ${error}`; }); } function uploadFile() { const formData = new FormData(); - formData.append('file', document.querySelector('#fileForm input[type="file"]').files[0]); + const fileInput = document.querySelector('#fileForm input[type="file"]'); + formData.append('file', fileInput.files[0]); fetch('/upload/file', { method: 'POST', body: formData, }) .then(response => response.json()) .then(data => { - document.getElementById('fileResult').innerHTML = `File uploaded. Download it here.`; - }); - } - - function uploadFolder() { - const files = document.querySelector('#folderForm input[type="file"]').files; - if (files.length === 0) { - alert('Please select a folder.'); - return; - } - - const formData = new FormData(); - for (const file of files) { - formData.append('file', file); - } - - fetch('/upload/folder', { - method: 'POST', - body: formData, + if (data.success) { + const simpleUrl = `${window.location.origin}/${data.vanity}`; + document.getElementById('fileResult').innerHTML = `File uploaded. Access it ${simpleUrl}`; + } else { + document.getElementById('fileResult').innerHTML = `Error: ${data.error}`; + } }) - .then(response => response.json()) - .then(data => { - document.getElementById('folderResult').innerHTML = `Folder uploaded. View its contents here.`; + .catch(error => { + console.error('Error:', error); + document.getElementById('fileResult').innerHTML = `An error occurred: ${error}`; }); } @@ -297,13 +656,21 @@ fetch('/shorten', { method: 'POST', headers: { - 'Content-Type': 'application/x-www-form-urlencoded', + 'Content-Type': 'application/json', }, - body: new URLSearchParams({ url }), + body: JSON.stringify({ url: url }), }) .then(response => response.json()) .then(data => { - document.getElementById('urlResult').innerHTML = `URL shortened. Access it here.`; + if (data.success) { + document.getElementById('urlResult').innerHTML = `URL shortened. Access it ${data.short_url}`; + } else { + document.getElementById('urlResult').innerHTML = `Error: ${data.error}`; + } + }) + .catch(error => { + console.error('Error:', error); + document.getElementById('urlResult').innerHTML = `An error occurred: ${error}`; }); }