From 8e3308039af90d941546a7985670053439aab665 Mon Sep 17 00:00:00 2001 From: Will Miao <13051207myq@gmail.com> Date: Sat, 29 Mar 2025 19:11:13 +0800 Subject: [PATCH] Refactor Lora handling in RecipeRoutes and enhance RecipeManager - Updated Lora filtering logic in RecipeRoutes to skip deleted LoRAs without exclusion checks, improving performance and clarity. - Enhanced condition for fetching cached LoRAs to ensure valid data is processed. - Added toggleApiKeyVisibility function to RecipeManager, improving API key management in the UI. --- py/routes/recipe_routes.py | 9 +++++++-- static/js/recipes.js | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/py/routes/recipe_routes.py b/py/routes/recipe_routes.py index b58b58ed..037f5c19 100644 --- a/py/routes/recipe_routes.py +++ b/py/routes/recipe_routes.py @@ -943,7 +943,10 @@ class RecipeRoutes: for lora in loras: # Skip loras that are deleted AND marked for exclusion - if lora.get("isDeleted", False) and lora.get("exclude", False): + if lora.get("isDeleted", False): + continue + + if not self.recipe_scanner._lora_scanner.has_lora_hash(lora.get("hash", "")): continue # Get the strength @@ -966,7 +969,9 @@ class RecipeRoutes: # Search for files with matching modelVersionId all_loras = await self.recipe_scanner._lora_scanner.get_cached_data() for cached_lora in all_loras.raw_data: - if "civitai" in cached_lora and cached_lora["civitai"].get("id") == lora.get("modelVersionId"): + if not cached_lora.get("civitai"): + continue + if cached_lora.get("civitai", {}).get("id") == lora.get("modelVersionId"): file_name = os.path.splitext(os.path.basename(cached_lora["path"]))[0] break diff --git a/static/js/recipes.js b/static/js/recipes.js index 39c2d1f7..15340c3b 100644 --- a/static/js/recipes.js +++ b/static/js/recipes.js @@ -4,6 +4,7 @@ import { ImportManager } from './managers/ImportManager.js'; import { RecipeCard } from './components/RecipeCard.js'; import { RecipeModal } from './components/RecipeModal.js'; import { getCurrentPageState } from './state/index.js'; +import { toggleApiKeyVisibility } from './managers/SettingsManager.js'; class RecipeManager { constructor() { @@ -54,6 +55,7 @@ class RecipeManager { // Only expose what's needed for the page window.recipeManager = this; window.importManager = this.importManager; + window.toggleApiKeyVisibility = toggleApiKeyVisibility; } initEventListeners() {