From fdec5355598348bf7c1c04a0ac0f3b2307372640 Mon Sep 17 00:00:00 2001 From: Will Miao <13051207myq@gmail.com> Date: Thu, 21 Aug 2025 11:52:46 +0800 Subject: [PATCH] fix: Normalize path separators in relative path handling for improved compatibility across platforms --- py/services/base_model_service.py | 8 ++++---- py/services/lora_service.py | 1 + web/comfyui/autocomplete.js | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/py/services/base_model_service.py b/py/services/base_model_service.py index f69b7893..cc7d10a9 100644 --- a/py/services/base_model_service.py +++ b/py/services/base_model_service.py @@ -398,12 +398,12 @@ class BaseModelService(ABC): relative_path = None for root in model_roots: # Normalize paths for comparison - normalized_root = os.path.normpath(root).replace(os.sep, '/') - normalized_file = os.path.normpath(file_path).replace(os.sep, '/') + normalized_root = os.path.normpath(root) + normalized_file = os.path.normpath(file_path) if normalized_file.startswith(normalized_root): - # Remove root and leading slash to get relative path - relative_path = normalized_file[len(normalized_root):].lstrip('/') + # Remove root and leading separator to get relative path + relative_path = normalized_file[len(normalized_root):].lstrip(os.sep) break if relative_path and search_lower in relative_path.lower(): diff --git a/py/services/lora_service.py b/py/services/lora_service.py index 32fa25e9..f4c71096 100644 --- a/py/services/lora_service.py +++ b/py/services/lora_service.py @@ -167,6 +167,7 @@ class LoraService(BaseModelService): if file_path: # Convert to forward slashes and extract relative path file_path_normalized = file_path.replace('\\', '/') + relative_path = relative_path.replace('\\', '/') # Find the relative path part by looking for the relative_path in the full path if file_path_normalized.endswith(relative_path) or relative_path in file_path_normalized: return lora.get('usage_tips', '') diff --git a/web/comfyui/autocomplete.js b/web/comfyui/autocomplete.js index 3b9bf0e3..f979521c 100644 --- a/web/comfyui/autocomplete.js +++ b/web/comfyui/autocomplete.js @@ -248,7 +248,7 @@ class AutoComplete { if (!this.previewTooltip) return; // Extract filename without extension for preview - const fileName = relativePath.split('/').pop(); + const fileName = relativePath.split(/[/\\]/).pop(); const loraName = fileName.replace(/\.(safetensors|ckpt|pt|bin)$/i, ''); // Get item position for tooltip positioning @@ -380,7 +380,7 @@ class AutoComplete { async insertSelection(relativePath) { // Extract just the filename for LoRA name - const fileName = relativePath.split('/').pop().replace(/\.(safetensors|ckpt|pt|bin)$/i, ''); + const fileName = relativePath.split(/[/\\]/).pop().replace(/\.(safetensors|ckpt|pt|bin)$/i, ''); // Get usage tips and extract strength let strength = 1.0; // Default strength