fix downloads

This commit is contained in:
2025-05-28 12:13:56 +02:00
parent 552d1feb2e
commit ef4b4ab39f
3 changed files with 38 additions and 7 deletions

View File

@@ -210,11 +210,41 @@ export class FileManager {
}
}
downloadFile(fileId) {
console.log('[FileManager] Downloading file:', fileId);
const url = `/api/rooms/${this.roomManager.roomId}/files/${fileId}/download`;
async downloadFile(filename, path = '') {
console.log('[FileManager] Downloading file:', { filename, path });
const url = `/api/rooms/${this.roomManager.roomId}/files/${encodeURIComponent(filename)}`;
if (path) {
url += `?path=${encodeURIComponent(path)}`;
}
console.log('[FileManager] Download URL:', url);
window.location.href = url;
try {
const response = await fetch(url, {
method: 'GET',
headers: {
'X-CSRF-Token': document.querySelector('meta[name="csrf-token"]').getAttribute('content')
}
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const blob = await response.blob();
const downloadUrl = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = downloadUrl;
a.download = filename;
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(downloadUrl);
document.body.removeChild(a);
console.log('[FileManager] Download initiated');
} catch (error) {
console.error('[FileManager] Error downloading file:', error);
document.getElementById('fileError').textContent = 'Failed to download file. Please try again.';
throw error;
}
}
async downloadSelected() {
@@ -238,13 +268,13 @@ export class FileManager {
}
try {
const response = await fetch(`/api/rooms/${this.roomManager.roomId}/files/download`, {
const response = await fetch(`/api/rooms/${this.roomManager.roomId}/download-zip`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRF-Token': document.querySelector('meta[name="csrf-token"]').getAttribute('content')
},
body: JSON.stringify({ file_ids: fileIds })
body: JSON.stringify({ items: selectedItems })
});
console.log('[FileManager] Download response status:', response.status);