fix downloads
This commit is contained in:
@@ -210,11 +210,41 @@ export class FileManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
downloadFile(fileId) {
|
async downloadFile(filename, path = '') {
|
||||||
console.log('[FileManager] Downloading file:', fileId);
|
console.log('[FileManager] Downloading file:', { filename, path });
|
||||||
const url = `/api/rooms/${this.roomManager.roomId}/files/${fileId}/download`;
|
const url = `/api/rooms/${this.roomManager.roomId}/files/${encodeURIComponent(filename)}`;
|
||||||
|
if (path) {
|
||||||
|
url += `?path=${encodeURIComponent(path)}`;
|
||||||
|
}
|
||||||
console.log('[FileManager] Download URL:', url);
|
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() {
|
async downloadSelected() {
|
||||||
@@ -238,13 +268,13 @@ export class FileManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
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',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'X-CSRF-Token': document.querySelector('meta[name="csrf-token"]').getAttribute('content')
|
'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);
|
console.log('[FileManager] Download response status:', response.status);
|
||||||
|
|
||||||
|
|||||||
@@ -87,6 +87,7 @@ export class ModalManager {
|
|||||||
|
|
||||||
console.log('[ModalManager] Found file:', file);
|
console.log('[ModalManager] Found file:', file);
|
||||||
return {
|
return {
|
||||||
|
id: file.id,
|
||||||
name: file.name,
|
name: file.name,
|
||||||
path: file.path || '',
|
path: file.path || '',
|
||||||
type: file.type
|
type: file.type
|
||||||
|
|||||||
@@ -247,7 +247,7 @@ export class ViewManager {
|
|||||||
} else {
|
} else {
|
||||||
if (this.roomManager.canDownload) {
|
if (this.roomManager.canDownload) {
|
||||||
actions.push(`
|
actions.push(`
|
||||||
<button class="btn btn-sm file-action-btn" title="Download" onclick="window.roomManager.fileManager.downloadFile('${file.id}')"
|
<button class="btn btn-sm file-action-btn" title="Download" onclick="window.roomManager.fileManager.downloadFile('${file.name}', '${file.path || ''}')"
|
||||||
style="background-color:var(--primary-opacity-8);color:var(--primary-color);">
|
style="background-color:var(--primary-opacity-8);color:var(--primary-color);">
|
||||||
<i class="fas fa-download"></i>
|
<i class="fas fa-download"></i>
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
Reference in New Issue
Block a user