Fix trash

This commit is contained in:
2025-05-26 21:36:27 +02:00
parent c00fe16b94
commit 0aadd1f5e9
3 changed files with 105 additions and 12 deletions

View File

@@ -400,16 +400,31 @@ function emptyTrash() {
return;
}
fetch('/api/rooms/empty-trash', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': csrfToken
}
})
// Get all trashed files to get their room IDs
fetch('/api/rooms/trash')
.then(r => r.json())
.then(res => {
if (res.success) {
.then(files => {
// Get unique room IDs
const roomIds = [...new Set(files.map(file => file.room_id))];
// Create an array of promises for emptying trash in each room
const emptyPromises = roomIds.map(roomId =>
fetch(`/api/rooms/${roomId}/trash/empty`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': csrfToken
}
})
);
// Execute all promises
return Promise.all(emptyPromises);
})
.then(responses => {
// Check if all responses were successful
const allSuccessful = responses.every(r => r.ok);
if (allSuccessful) {
// Clear all files from the current view
currentFiles = [];
renderFiles(currentFiles);
@@ -417,7 +432,7 @@ function emptyTrash() {
const modal = bootstrap.Modal.getInstance(document.getElementById('emptyTrashModal'));
modal.hide();
} else {
console.error('Failed to empty trash:', res.error);
console.error('Failed to empty trash in some rooms');
}
})
.catch(error => {