Added events system

This commit is contained in:
2025-05-29 14:27:15 +02:00
parent 3174f8fa5b
commit f00d569db3
24 changed files with 1186 additions and 114 deletions

View File

@@ -354,6 +354,24 @@ function toggleStar(filename, path = '', roomId) {
.then(r => r.json())
.then(res => {
if (res.success) {
// Log the star/unstar event
fetch('/api/events/log', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': csrfToken
},
body: JSON.stringify({
event_type: res.starred ? 'file_star' : 'file_unstar',
details: {
filename: filename,
path: path,
room_id: roomId,
timestamp: new Date().toISOString()
}
})
});
// Remove the file from the current view since it's no longer starred
currentFiles = currentFiles.filter(f => !(f.name === filename && f.path === path && f.room_id === roomId));
renderFiles(currentFiles);
@@ -394,6 +412,24 @@ function restoreFile(filename, path = '', roomId) {
.then(r => r.json())
.then(res => {
if (res.success) {
// Log the restore event
fetch('/api/events/log', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': csrfToken
},
body: JSON.stringify({
event_type: 'file_restore',
details: {
filename: filename,
path: path,
room_id: roomId,
timestamp: new Date().toISOString()
}
})
});
// Remove the file from the current view since it's been restored
currentFiles = currentFiles.filter(f => !(f.name === filename && f.path === path && f.room_id === roomId));
renderFiles(currentFiles);
@@ -434,7 +470,7 @@ function permanentDeleteFile() {
return;
}
fetch(`/api/rooms/${roomId}/delete-permanent`, {
fetch(`/api/rooms/${roomId}/delete_permanent`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
@@ -445,39 +481,40 @@ function permanentDeleteFile() {
path: path
})
})
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
// Check if the response is empty
const contentType = response.headers.get('content-type');
if (contentType && contentType.includes('application/json')) {
return response.json();
}
return { success: true }; // If no JSON response, assume success
})
.then(r => r.json())
.then(res => {
if (res.success) {
// Remove the file from the current view since it's been deleted
// Log the permanent delete event
fetch('/api/events/log', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': csrfToken
},
body: JSON.stringify({
event_type: 'file_delete_permanent',
details: {
filename: filename,
path: path,
room_id: roomId,
timestamp: new Date().toISOString()
}
})
});
// Remove the file from the current view
currentFiles = currentFiles.filter(f => !(f.name === filename && f.path === path && f.room_id === roomId));
renderFiles(currentFiles);
// Close the modal
const modal = bootstrap.Modal.getInstance(document.getElementById('permanentDeleteModal'));
if (modal) {
modal.hide();
}
modal.hide();
} else {
console.error('Failed to delete file:', res.error || 'Unknown error');
console.error('Failed to delete file permanently:', res.error);
}
})
.catch(error => {
console.error('Error deleting file:', error);
// Show error to user
const modal = bootstrap.Modal.getInstance(document.getElementById('permanentDeleteModal'));
if (modal) {
modal.hide();
}
// You might want to show an error message to the user here
console.error('Error deleting file permanently:', error);
});
}