mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-08-14 09:43:22 -03:00
fix(update): resolve template path when updating to a different base model (#1059)
Version-tab updates reused the current version's folder, so updating a LoRA to a version with a different base model (e.g. Illustrious -> Anima) ignored the download path template and landed in the old version's directory. When the target version's base model differs from the current local version and a path template is configured, re-resolve the template under the same model root. The backend keeps an explicitly provided root when use_save_dir_as_root is set, so regular downloads still use the default root.
This commit is contained in:
@@ -83,6 +83,7 @@ class DownloadCoordinator:
|
||||
save_dir=payload.get("model_root"),
|
||||
relative_path=payload.get("relative_path", ""),
|
||||
use_default_paths=payload.get("use_default_paths", False),
|
||||
use_save_dir_as_root=payload.get("use_save_dir_as_root", False),
|
||||
progress_callback=progress_callback,
|
||||
download_id=download_id,
|
||||
source=payload.get("source"),
|
||||
|
||||
@@ -217,6 +217,7 @@ class DownloadManager:
|
||||
download_id: str | None = None,
|
||||
source: str | None = None,
|
||||
file_params: Dict[str, Any] | None = None,
|
||||
use_save_dir_as_root: bool = False,
|
||||
) -> Dict[str, Any]:
|
||||
"""Download model from Civitai with task tracking and concurrency control
|
||||
|
||||
@@ -257,6 +258,7 @@ class DownloadManager:
|
||||
"save_dir": save_dir,
|
||||
"relative_path": relative_path,
|
||||
"use_default_paths": bool(use_default_paths),
|
||||
"use_save_dir_as_root": bool(use_save_dir_as_root),
|
||||
"source": source,
|
||||
"file_params": copy.deepcopy(file_params) if file_params is not None else None,
|
||||
"progress": 0,
|
||||
@@ -287,6 +289,7 @@ class DownloadManager:
|
||||
use_default_paths,
|
||||
source,
|
||||
file_params,
|
||||
use_save_dir_as_root,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -321,6 +324,7 @@ class DownloadManager:
|
||||
use_default_paths: bool = False,
|
||||
source: str | None = None,
|
||||
file_params: Dict[str, Any] | None = None,
|
||||
use_save_dir_as_root: bool = False,
|
||||
):
|
||||
"""Execute download with semaphore to limit concurrency"""
|
||||
# Update status to waiting
|
||||
@@ -401,6 +405,7 @@ class DownloadManager:
|
||||
),
|
||||
source,
|
||||
file_params,
|
||||
use_save_dir_as_root=use_save_dir_as_root,
|
||||
)
|
||||
|
||||
# Update status based on result
|
||||
@@ -621,6 +626,7 @@ class DownloadManager:
|
||||
"save_dir": info.get("save_dir"),
|
||||
"relative_path": info.get("relative_path", ""),
|
||||
"use_default_paths": bool(info.get("use_default_paths", False)),
|
||||
"use_save_dir_as_root": bool(info.get("use_save_dir_as_root", False)),
|
||||
"source": info.get("source"),
|
||||
"file_params": copy.deepcopy(info.get("file_params")),
|
||||
"transfer_backend": info.get("transfer_backend", "aria2"),
|
||||
@@ -643,6 +649,7 @@ class DownloadManager:
|
||||
"save_dir": record.get("save_dir"),
|
||||
"relative_path": record.get("relative_path", ""),
|
||||
"use_default_paths": bool(record.get("use_default_paths", False)),
|
||||
"use_save_dir_as_root": bool(record.get("use_save_dir_as_root", False)),
|
||||
"source": record.get("source"),
|
||||
"file_params": copy.deepcopy(record.get("file_params")),
|
||||
"progress": record.get("progress", 0),
|
||||
@@ -1001,6 +1008,7 @@ class DownloadManager:
|
||||
bool(restored.get("use_default_paths", False)),
|
||||
restored.get("source"),
|
||||
restored.get("file_params"),
|
||||
bool(restored.get("use_save_dir_as_root", False)),
|
||||
)
|
||||
)
|
||||
continue
|
||||
@@ -1134,6 +1142,7 @@ class DownloadManager:
|
||||
transfer_backend: str = "python",
|
||||
source: str | None = None,
|
||||
file_params: Dict[str, Any] | None = None,
|
||||
use_save_dir_as_root: bool = False,
|
||||
) -> Dict[str, Any]:
|
||||
"""Wrapper for original download_from_civitai implementation"""
|
||||
try:
|
||||
@@ -1362,36 +1371,41 @@ class DownloadManager:
|
||||
# Handle use_default_paths
|
||||
if use_default_paths:
|
||||
settings_manager = get_settings_manager()
|
||||
# Set save_dir based on model type
|
||||
if model_type == "checkpoint":
|
||||
if is_diffusion_model:
|
||||
default_path = settings_manager.get("default_unet_root")
|
||||
error_msg = "Default unet root path not set in settings"
|
||||
else:
|
||||
default_path = settings_manager.get("default_checkpoint_root")
|
||||
error_msg = "Default checkpoint root path not set in settings"
|
||||
if not default_path:
|
||||
return {
|
||||
"success": False,
|
||||
"error": error_msg,
|
||||
}
|
||||
save_dir = default_path
|
||||
elif model_type == "lora":
|
||||
default_path = settings_manager.get("default_lora_root")
|
||||
if not default_path:
|
||||
return {
|
||||
"success": False,
|
||||
"error": "Default lora root path not set in settings",
|
||||
}
|
||||
save_dir = default_path
|
||||
elif model_type == "embedding":
|
||||
default_path = settings_manager.get("default_embedding_root")
|
||||
if not default_path:
|
||||
return {
|
||||
"success": False,
|
||||
"error": "Default embedding root path not set in settings",
|
||||
}
|
||||
save_dir = default_path
|
||||
# With use_save_dir_as_root, an explicitly provided save_dir is kept
|
||||
# as the base root and the path template is resolved underneath it.
|
||||
# Otherwise fall back to the configured default root, which keeps the
|
||||
# classic "download to default root" behavior for regular downloads.
|
||||
if not save_dir or not use_save_dir_as_root:
|
||||
# Set save_dir based on model type
|
||||
if model_type == "checkpoint":
|
||||
if is_diffusion_model:
|
||||
default_path = settings_manager.get("default_unet_root")
|
||||
error_msg = "Default unet root path not set in settings"
|
||||
else:
|
||||
default_path = settings_manager.get("default_checkpoint_root")
|
||||
error_msg = "Default checkpoint root path not set in settings"
|
||||
if not default_path:
|
||||
return {
|
||||
"success": False,
|
||||
"error": error_msg,
|
||||
}
|
||||
save_dir = default_path
|
||||
elif model_type == "lora":
|
||||
default_path = settings_manager.get("default_lora_root")
|
||||
if not default_path:
|
||||
return {
|
||||
"success": False,
|
||||
"error": "Default lora root path not set in settings",
|
||||
}
|
||||
save_dir = default_path
|
||||
elif model_type == "embedding":
|
||||
default_path = settings_manager.get("default_embedding_root")
|
||||
if not default_path:
|
||||
return {
|
||||
"success": False,
|
||||
"error": "Default embedding root path not set in settings",
|
||||
}
|
||||
save_dir = default_path
|
||||
|
||||
# Calculate relative path using template
|
||||
relative_path = self._calculate_relative_path(version_info, model_type)
|
||||
@@ -2761,6 +2775,7 @@ class DownloadManager:
|
||||
bool(persisted.get("use_default_paths", False)),
|
||||
persisted.get("source"),
|
||||
persisted.get("file_params"),
|
||||
bool(persisted.get("use_save_dir_as_root", False)),
|
||||
),
|
||||
)
|
||||
except Exception as exc:
|
||||
|
||||
Reference in New Issue
Block a user