diff --git a/py/routes/recipe_routes.py b/py/routes/recipe_routes.py index d43e1972..38071d7d 100644 --- a/py/routes/recipe_routes.py +++ b/py/routes/recipe_routes.py @@ -550,7 +550,7 @@ class RecipeRoutes: with open(image_path, 'wb') as f: f.write(optimized_image) - # Create the recipe JSON + # Create the recipe data structure current_time = time.time() # Format loras data according to the recipe.json format @@ -606,6 +606,10 @@ class RecipeRoutes: if tags: recipe_data["tags"] = tags + # Add source_path if provided in metadata + if metadata.get("source_path"): + recipe_data["source_path"] = metadata.get("source_path") + # Save the recipe JSON json_filename = f"{recipe_id}.recipe.json" json_path = os.path.join(recipes_dir, json_filename) diff --git a/py/utils/lora_metadata.py b/py/utils/lora_metadata.py index f221562d..3dcecd75 100644 --- a/py/utils/lora_metadata.py +++ b/py/utils/lora_metadata.py @@ -2,6 +2,9 @@ from safetensors import safe_open from typing import Dict from .model_utils import determine_base_model import os +import logging + +logger = logging.getLogger(__name__) async def extract_lora_metadata(file_path: str) -> Dict: """Extract essential metadata from safetensors file""" diff --git a/static/js/managers/ImportManager.js b/static/js/managers/ImportManager.js index db28b4aa..ae39a141 100644 --- a/static/js/managers/ImportManager.js +++ b/static/js/managers/ImportManager.js @@ -907,17 +907,17 @@ export class ImportManager { } try { - this.loadingManager.showSimpleLoading(isDownloadOnly ? 'Preparing download...' : 'Saving recipe...'); + // Show progress indicator + this.loadingManager.showSimpleLoading(isDownloadOnly ? 'Downloading LoRAs...' : 'Saving recipe...'); - // If we're only downloading LoRAs for an existing recipe, skip the recipe save step + // Only send the complete recipe to save if not in download-only mode if (!isDownloadOnly) { - // First save the recipe - // Create form data for save request + // Create FormData object for saving recipe const formData = new FormData(); - // Handle image data - either from file upload or from URL mode + // Add image data - depends on import mode if (this.recipeImage) { - // File upload mode + // Direct upload formData.append('image', this.recipeImage); } else if (this.recipeData && this.recipeData.image_base64) { // URL mode with base64 data @@ -945,6 +945,15 @@ export class ImportManager { raw_metadata: this.recipeData.raw_metadata || {} }; + // Add source_path to metadata to track where the recipe was imported from + if (this.importMode === 'url') { + const urlInput = document.getElementById('imageUrlInput'); + console.log("urlInput.value", urlInput.value); + if (urlInput && urlInput.value) { + completeMetadata.source_path = urlInput.value; + } + } + formData.append('metadata', JSON.stringify(completeMetadata)); // Send save request