Fix trash
This commit is contained in:
@@ -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 => {
|
||||
|
||||
Reference in New Issue
Block a user