Added cron job, updated webserver, added retry functionality

This commit is contained in:
Myx
2023-10-13 02:42:04 +02:00
parent e3f9dc2899
commit d25d2c8f54
7 changed files with 219 additions and 31 deletions

View File

@@ -1,3 +1,57 @@
function loadFiles() {
// Fetch the JSON data from the /sounds endpoint
fetch('/sounds')
.then(response => response.json())
.then(data => {
// Get the fileList element
const fileList = document.getElementById('fileList');
// Clear the current list
fileList.innerHTML = '';
// Add each file to the list
data.forEach(file => {
// Create a new list item
const li = document.createElement('li');
li.className = 'grid-x';
// Create a div for the file name and add it to the list item
const fileNameDiv = document.createElement('div');
fileNameDiv.className = 'cell auto';
fileNameDiv.textContent = file;
li.appendChild(fileNameDiv);
// Create a div for the trash icon and add it to the list item
const trashIconDiv = document.createElement('div');
trashIconDiv.className = 'cell shrink';
trashIconDiv.style.cursor = 'pointer';
trashIconDiv.textContent = '🗑️';
li.appendChild(trashIconDiv);
// Attach a click event listener to the trash icon div
trashIconDiv.addEventListener('click', () => {
// Send a DELETE request to the server to remove the file
fetch('/sounds/' + file, { method: 'DELETE' })
.then(response => response.text())
.then(message => {
console.log(message);
// Remove the list item from the fileList element
fileList.removeChild(li);
})
.catch(error => console.error('Error:', error));
});
// Add the list item to the fileList element
fileList.appendChild(li);
});
})
.catch(error => console.error('Error:', error));
}
// Call loadFiles when the script is loaded
loadFiles();
document.getElementById('uploadForm').addEventListener('submit', function(event) {
event.preventDefault();
@@ -37,10 +91,13 @@ document.getElementById('uploadForm').addEventListener('submit', function(event)
.then(data => {
console.log(data);
alert('File uploaded successfully.');
// Call loadFiles again to update the file list
loadFiles();
})
.catch(error => {
console.error(error);
alert('An error occurred while uploading the file.');
});
});
});
});