From f8ba551cc4e3d40f5290876712cdda4791979c23 Mon Sep 17 00:00:00 2001 From: pixelpaws Date: Sun, 5 Oct 2025 15:49:18 +0800 Subject: [PATCH] fix(recipes): use preview endpoint for recipe images --- py/routes/handlers/recipe_handlers.py | 14 ++++++-------- py/services/recipe_scanner.py | 17 +++++++---------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/py/routes/handlers/recipe_handlers.py b/py/routes/handlers/recipe_handlers.py index aa912477..d8cebb2c 100644 --- a/py/routes/handlers/recipe_handlers.py +++ b/py/routes/handlers/recipe_handlers.py @@ -206,18 +206,16 @@ class RecipeListingHandler: def format_recipe_file_url(self, file_path: str) -> str: try: - recipes_dir = os.path.join(config.loras_roots[0], "recipes").replace(os.sep, "/") - normalized_path = file_path.replace(os.sep, "/") - if normalized_path.startswith(recipes_dir): - relative_path = os.path.relpath(file_path, config.loras_roots[0]).replace(os.sep, "/") - return f"/loras_static/root1/preview/{relative_path}" - - file_name = os.path.basename(file_path) - return f"/loras_static/root1/preview/recipes/{file_name}" + normalized_path = os.path.normpath(file_path) + static_url = config.get_preview_static_url(normalized_path) + if static_url: + return static_url except Exception as exc: # pragma: no cover - logging path self._logger.error("Error formatting recipe file URL: %s", exc, exc_info=True) return "/loras_static/images/no-preview.png" + return "/loras_static/images/no-preview.png" + class RecipeQueryHandler: """Provide read-only insights on recipe data.""" diff --git a/py/services/recipe_scanner.py b/py/services/recipe_scanner.py index 58894364..a9eeb0fb 100644 --- a/py/services/recipe_scanner.py +++ b/py/services/recipe_scanner.py @@ -742,20 +742,17 @@ class RecipeScanner: """Format file path as URL for serving in web UI""" if not file_path: return '/loras_static/images/no-preview.png' - + try: - # Format file path as a URL that will work with static file serving - recipes_dir = os.path.join(config.loras_roots[0], "recipes").replace(os.sep, '/') - if file_path.replace(os.sep, '/').startswith(recipes_dir): - relative_path = os.path.relpath(file_path, config.loras_roots[0]).replace(os.sep, '/') - return f"/loras_static/root1/preview/{relative_path}" - - # If not in recipes dir, try to create a valid URL from the file name - file_name = os.path.basename(file_path) - return f"/loras_static/root1/preview/recipes/{file_name}" + normalized_path = os.path.normpath(file_path) + static_url = config.get_preview_static_url(normalized_path) + if static_url: + return static_url except Exception as e: logger.error(f"Error formatting file URL: {e}") return '/loras_static/images/no-preview.png' + + return '/loras_static/images/no-preview.png' def _format_timestamp(self, timestamp: float) -> str: """Format timestamp for display"""