Add cache management feature: implement clear cache API and modal confirmation

This commit is contained in:
Will Miao
2025-05-29 14:36:13 +08:00
parent afb012029f
commit ddf132bd78
5 changed files with 136 additions and 2 deletions

View File

@@ -170,6 +170,18 @@ export class ModalManager {
});
}
// Add clearCacheModal registration
const clearCacheModal = document.getElementById('clearCacheModal');
if (clearCacheModal) {
this.registerModal('clearCacheModal', {
element: clearCacheModal,
onClose: () => {
this.getModal('clearCacheModal').element.classList.remove('show');
document.body.classList.remove('modal-open');
}
});
}
// Set up event listeners for modal toggles
const supportToggle = document.getElementById('supportToggleBtn');
if (supportToggle) {
@@ -233,7 +245,7 @@ export class ModalManager {
// Store current scroll position before showing modal
this.scrollPosition = window.scrollY;
if (id === 'deleteModal' || id === 'excludeModal' || id === 'duplicateDeleteModal') {
if (id === 'deleteModal' || id === 'excludeModal' || id === 'duplicateDeleteModal' || id === 'clearCacheModal') {
modal.element.classList.add('show');
} else {
modal.element.style.display = 'block';

View File

@@ -341,6 +341,37 @@ export class SettingsManager {
}
}
confirmClearCache() {
// Show confirmation modal
modalManager.showModal('clearCacheModal');
}
async executeClearCache() {
try {
// Call the API endpoint to clear cache files
const response = await fetch('/api/clear-cache', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
}
});
const result = await response.json();
if (result.success) {
showToast('Cache files have been cleared successfully. Cache will rebuild on next action.', 'success');
} else {
showToast(`Failed to clear cache: ${result.error}`, 'error');
}
// Close the confirmation modal
modalManager.closeModal('clearCacheModal');
} catch (error) {
showToast(`Error clearing cache: ${error.message}`, 'error');
modalManager.closeModal('clearCacheModal');
}
}
async reloadContent() {
if (this.currentPage === 'loras') {
// Reload the loras without updating folders