From c66cbc800be674e8ca99f71606b8430e58c2b914 Mon Sep 17 00:00:00 2001 From: Will Miao <13051207myq@gmail.com> Date: Thu, 11 Sep 2025 15:21:06 +0800 Subject: [PATCH] refactor: remove clear cache functionality and associated modal from settings manager --- py/routes/misc_routes.py | 50 ------------------- static/js/managers/SettingsManager.js | 26 ---------- .../components/modals/confirm_modals.html | 15 ------ 3 files changed, 91 deletions(-) diff --git a/py/routes/misc_routes.py b/py/routes/misc_routes.py index 5a53fea9..2178d7cd 100644 --- a/py/routes/misc_routes.py +++ b/py/routes/misc_routes.py @@ -13,8 +13,6 @@ from ..utils.constants import SUPPORTED_MEDIA_EXTENSIONS, NODE_TYPES, DEFAULT_NO from ..services.service_registry import ServiceRegistry from ..services.metadata_service import get_metadata_archive_manager, update_metadata_providers from ..services.websocket_manager import ws_manager -import re - logger = logging.getLogger(__name__) standalone_mode = 'nodes' not in sys.modules @@ -89,9 +87,6 @@ class MiscRoutes: def setup_routes(app): """Register miscellaneous routes""" app.router.add_post('/api/settings', MiscRoutes.update_settings) - - # Add new route for clearing cache - app.router.add_post('/api/clear-cache', MiscRoutes.clear_cache) app.router.add_get('/api/health-check', lambda request: web.json_response({'status': 'ok'})) @@ -120,51 +115,6 @@ class MiscRoutes: app.router.add_post('/api/remove-metadata-archive', MiscRoutes.remove_metadata_archive) app.router.add_get('/api/metadata-archive-status', MiscRoutes.get_metadata_archive_status) - @staticmethod - async def clear_cache(request): - """Clear all cache files from the cache folder""" - try: - # Get the cache folder path (relative to project directory) - project_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) - cache_folder = os.path.join(project_dir, 'cache') - - # Check if cache folder exists - if not os.path.exists(cache_folder): - logger.info("Cache folder does not exist, nothing to clear") - return web.json_response({'success': True, 'message': 'No cache folder found'}) - - # Get list of cache files before deleting for reporting - cache_files = [f for f in os.listdir(cache_folder) if os.path.isfile(os.path.join(cache_folder, f))] - deleted_files = [] - - # Delete each .msgpack file in the cache folder - for filename in cache_files: - if filename.endswith('.msgpack'): - file_path = os.path.join(cache_folder, filename) - try: - os.remove(file_path) - deleted_files.append(filename) - logger.info(f"Deleted cache file: {filename}") - except Exception as e: - logger.error(f"Failed to delete {filename}: {e}") - return web.json_response({ - 'success': False, - 'error': f"Failed to delete {filename}: {str(e)}" - }, status=500) - - return web.json_response({ - 'success': True, - 'message': f"Successfully cleared {len(deleted_files)} cache files", - 'deleted_files': deleted_files - }) - - except Exception as e: - logger.error(f"Error clearing cache files: {e}", exc_info=True) - return web.json_response({ - 'success': False, - 'error': str(e) - }, status=500) - @staticmethod async def update_settings(request): """Update application settings""" diff --git a/static/js/managers/SettingsManager.js b/static/js/managers/SettingsManager.js index 6ef0e404..2d477d24 100644 --- a/static/js/managers/SettingsManager.js +++ b/static/js/managers/SettingsManager.js @@ -1275,32 +1275,6 @@ export class SettingsManager { 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('toast.settings.cacheCleared', {}, 'success'); - } else { - showToast('toast.settings.cacheClearFailed', { error: result.error }, 'error'); - } - - // Close the confirmation modal - modalManager.closeModal('clearCacheModal'); - } catch (error) { - showToast('toast.settings.cacheClearError', { message: error.message }, 'error'); - modalManager.closeModal('clearCacheModal'); - } - } - async reloadContent() { if (this.currentPage === 'loras') { // Reload the loras without updating folders diff --git a/templates/components/modals/confirm_modals.html b/templates/components/modals/confirm_modals.html index a236d2c5..0da2ffe9 100644 --- a/templates/components/modals/confirm_modals.html +++ b/templates/components/modals/confirm_modals.html @@ -54,21 +54,6 @@ - -