fix trashing in rooms
This commit is contained in:
@@ -44,35 +44,49 @@ export class FileManager {
|
||||
}
|
||||
}
|
||||
|
||||
async deleteFile(fileId) {
|
||||
console.log('[FileManager] Deleting file:', fileId);
|
||||
async deleteFile(filename, path = '') {
|
||||
console.log('[FileManager] Deleting file:', { filename, path });
|
||||
const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/rooms/${this.roomManager.roomId}/files/${fileId}`, {
|
||||
let url = `/api/rooms/${this.roomManager.roomId}/files/${encodeURIComponent(filename)}`;
|
||||
if (path) {
|
||||
url += `?path=${encodeURIComponent(path)}`;
|
||||
}
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
'X-CSRF-Token': document.querySelector('meta[name="csrf-token"]').getAttribute('content')
|
||||
'X-CSRFToken': csrfToken
|
||||
}
|
||||
});
|
||||
console.log('[FileManager] Delete response status:', response.status);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
const result = await response.json();
|
||||
console.log('[FileManager] Delete result:', result);
|
||||
|
||||
if (result.success) {
|
||||
this.currentFiles = this.currentFiles.filter(file => file.id !== fileId);
|
||||
await this.roomManager.viewManager.renderFiles(this.currentFiles);
|
||||
console.log('[FileManager] File deleted and view updated');
|
||||
return { success: true, message: 'File moved to trash' };
|
||||
console.log('[FileManager] File deleted successfully');
|
||||
await this.fetchFiles();
|
||||
// Clear any existing error message
|
||||
const errorEl = document.getElementById('fileError');
|
||||
if (errorEl) {
|
||||
errorEl.textContent = '';
|
||||
}
|
||||
} else {
|
||||
throw new Error(result.message || 'Failed to delete file');
|
||||
console.error('[FileManager] Failed to delete file:', result.error);
|
||||
const errorEl = document.getElementById('fileError');
|
||||
if (errorEl) {
|
||||
errorEl.textContent = result.error || 'Failed to delete file.';
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('[FileManager] Error deleting file:', error);
|
||||
return { success: false, message: error.message };
|
||||
const errorEl = document.getElementById('fileError');
|
||||
if (errorEl) {
|
||||
errorEl.textContent = 'Failed to delete file. Please try again.';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user