more commits..

This commit is contained in:
pika 2025-03-23 03:53:45 +01:00
parent 6dda02141e
commit 7823be6481
20 changed files with 1835 additions and 631 deletions

View file

@ -470,4 +470,143 @@ document.addEventListener('DOMContentLoaded', function () {
});
}
}
// File upload functionality
const uploadBtn = document.querySelector('.btn.primary [class*="fa-upload"]');
const fileInput = document.getElementById('file-upload');
// Check if we're on upload page or have upload elements
if (uploadBtn && fileInput) {
uploadBtn.addEventListener('click', function (e) {
// Trigger the hidden file input
fileInput.click();
});
fileInput.addEventListener('change', function () {
if (this.files.length) {
handleFileUpload(this.files);
}
});
// Setup drag and drop zone if exists
const dropzone = document.getElementById('dropzone');
if (dropzone) {
setupDragAndDrop(dropzone);
}
}
// Handle file upload process
function handleFileUpload(files) {
// Show progress indicator
showUploadProgress();
const formData = new FormData();
// Add all files to FormData
for (let i = 0; i < files.length; i++) {
formData.append('file', files[i]);
}
// Get current folder ID from URL if available
const urlParams = new URLSearchParams(window.location.search);
const folderId = urlParams.get('folder_id');
if (folderId) {
formData.append('folder_id', folderId);
}
// Submit the upload
fetch('/files/upload', {
method: 'POST',
body: formData
})
.then(response => {
if (!response.ok) {
throw new Error('Upload failed');
}
return response.json();
})
.then(data => {
if (data.success) {
// Show success message
showUploadSuccess();
// Refresh the page to show the new file
setTimeout(() => {
window.location.reload();
}, 1000);
} else {
showUploadError(data.error || 'Upload failed');
}
})
.catch(error => {
console.error('Error:', error);
showUploadError('An error occurred during upload');
})
.finally(() => {
// Hide progress indicator
hideUploadProgress();
});
}
// Setup drag and drop functionality
function setupDragAndDrop(dropzone) {
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
dropzone.addEventListener(eventName, preventDefaults, false);
});
function preventDefaults(e) {
e.preventDefault();
e.stopPropagation();
}
['dragenter', 'dragover'].forEach(eventName => {
dropzone.addEventListener(eventName, highlight, false);
});
['dragleave', 'drop'].forEach(eventName => {
dropzone.addEventListener(eventName, unhighlight, false);
});
function highlight() {
dropzone.classList.add('highlight');
}
function unhighlight() {
dropzone.classList.remove('highlight');
}
dropzone.addEventListener('drop', handleDrop, false);
function handleDrop(e) {
const dt = e.dataTransfer;
const files = dt.files;
if (files.length > 0) {
handleFileUpload(files);
}
}
}
// UI feedback functions
function showUploadProgress() {
// Implementation depends on your UI
console.log('Uploading...');
// Could show a toast notification or progress bar
}
function hideUploadProgress() {
// Hide any progress indicators
}
function showUploadSuccess() {
// Show success message
console.log('Upload successful!');
}
function showUploadError(message) {
// Show error message
console.error('Upload error:', message);
alert('Upload failed: ' + message);
}
});