From a32940bcf63056479aad6c199724d63adf781ed5 Mon Sep 17 00:00:00 2001 From: Will Miao <13051207myq@gmail.com> Date: Fri, 14 Feb 2025 13:58:12 +0800 Subject: [PATCH] Enhance folder management in Lora API and UI; update folder tags dynamically and improve cache handling --- routes/api_routes.py | 6 +++- services/file_monitor.py | 3 -- static/js/api/loraApi.js | 51 +++++++++++++++++++++++---- static/js/managers/DownloadManager.js | 2 +- utils/model_utils.py | 3 +- 5 files changed, 53 insertions(+), 12 deletions(-) diff --git a/routes/api_routes.py b/routes/api_routes.py index 8f6f455c..e369644a 100644 --- a/routes/api_routes.py +++ b/routes/api_routes.py @@ -147,13 +147,17 @@ class ApiRoutes: self._format_lora_response(item) for item in result['items'] ] + + # Get all available folders from cache + cache = await self.scanner.get_cached_data() return web.json_response({ 'items': formatted_items, 'total': result['total'], 'page': result['page'], 'page_size': result['page_size'], - 'total_pages': result['total_pages'] + 'total_pages': result['total_pages'], + 'folders': cache.folders }) except Exception as e: diff --git a/services/file_monitor.py b/services/file_monitor.py index f5045d4e..1e809935 100644 --- a/services/file_monitor.py +++ b/services/file_monitor.py @@ -25,14 +25,11 @@ class LoraFileHandler(FileSystemEventHandler): def _should_ignore(self, path: str) -> bool: """Check if path should be ignored""" - logger.info(f"Checking ignore for {path}") - logger.info(f"Ignore paths: {self._ignore_paths}") return path.replace(os.sep, '/') in self._ignore_paths def add_ignore_path(self, path: str, file_size: int = 0): """Add path to ignore list with dynamic timeout based on file size""" self._ignore_paths.add(path.replace(os.sep, '/')) - logger.info(f"Update ignore paths: {self._ignore_paths}") # Calculate timeout based on file size, with a minimum value # Assuming average download speed of 1MB/s diff --git a/static/js/api/loraApi.js b/static/js/api/loraApi.js index 457315df..4abeaac5 100644 --- a/static/js/api/loraApi.js +++ b/static/js/api/loraApi.js @@ -4,7 +4,7 @@ import { createLoraCard } from '../components/LoraCard.js'; import { initializeInfiniteScroll } from '../utils/infiniteScroll.js'; import { showDeleteModal } from '../utils/modalUtils.js'; -export async function loadMoreLoras() { +export async function loadMoreLoras(boolUpdateFolders = false) { if (state.isLoading || !state.hasMore) return; state.isLoading = true; @@ -56,6 +56,10 @@ export async function loadMoreLoras() { } else { state.hasMore = false; } + + if (boolUpdateFolders && data.folders) { + updateFolderTags(data.folders); + } } catch (error) { console.error('Error loading loras:', error); @@ -65,6 +69,39 @@ export async function loadMoreLoras() { } } +function updateFolderTags(folders) { + const folderTagsContainer = document.querySelector('.folder-tags'); + if (!folderTagsContainer) return; + + // Keep track of currently selected folder + const currentFolder = state.activeFolder; + + // Create HTML for folder tags + const tagsHTML = folders.map(folder => { + const isActive = folder === currentFolder; + return `