Unify metadata workflow cache and category handling
This commit is contained in:
@@ -14,6 +14,7 @@ from ..request_utils import (
|
||||
read_text_field,
|
||||
)
|
||||
from ..routes.context import RouteContext
|
||||
from ..type_utils import CATEGORY_MAP, normalize_category_token
|
||||
from ..workflow.formats import normalize_workflow_payload
|
||||
|
||||
MAX_IMAGE_BYTES = 64 * 1024 * 1024
|
||||
@@ -25,22 +26,6 @@ _CIVITAI_JSON_LABELS = (
|
||||
"Civitai metadata",
|
||||
"Civitai resources",
|
||||
)
|
||||
_CIVITAI_CATEGORY_ALIASES = {
|
||||
"checkpoint": "checkpoints",
|
||||
"checkpoints": "checkpoints",
|
||||
"lora": "loras",
|
||||
"loras": "loras",
|
||||
"vae": "vae",
|
||||
"controlnet": "controlnet",
|
||||
"embedding": "embeddings",
|
||||
"embeddings": "embeddings",
|
||||
"textualinversion": "embeddings",
|
||||
"upscale": "upscale_models",
|
||||
"upscaler": "upscale_models",
|
||||
"upscalemodel": "upscale_models",
|
||||
}
|
||||
|
||||
|
||||
def _decode_exif_user_comment(value: bytes) -> str:
|
||||
"""Decode the standard EXIF UserComment prefix and payload."""
|
||||
if value.startswith(b"UNICODE"):
|
||||
@@ -268,8 +253,8 @@ def _normalize_civitai_resource(value: Any, index: int) -> Optional[dict[str, An
|
||||
resource_type = str(
|
||||
_first_mapping_value(value, ("type", "model_type", "modelType")) or ""
|
||||
).strip()
|
||||
category_key = re.sub(r"[^a-z0-9]+", "", resource_type.lower())
|
||||
category = _CIVITAI_CATEGORY_ALIASES.get(category_key, category_key or "unknown")
|
||||
category_key = normalize_category_token(resource_type)
|
||||
category = CATEGORY_MAP.get(category_key, category_key or "unknown")
|
||||
model_version_id = _coerce_identifier(
|
||||
_first_mapping_value(
|
||||
value,
|
||||
|
||||
@@ -242,6 +242,7 @@ URN_TYPE_MAP = {
|
||||
CATEGORY_MAP = {
|
||||
"checkpoints": "checkpoints",
|
||||
"checkpoint": "checkpoints",
|
||||
"ckpt": "checkpoints",
|
||||
"loras": "loras",
|
||||
"lora": "loras",
|
||||
"embeddings": "embeddings",
|
||||
@@ -254,7 +255,9 @@ CATEGORY_MAP = {
|
||||
"control_net": "controlnet",
|
||||
"vae": "vae",
|
||||
"upscaler": "upscale_models",
|
||||
"upscale": "upscale_models",
|
||||
"upscale_model": "upscale_models",
|
||||
"upscalemodel": "upscale_models",
|
||||
"upscale_models": "upscale_models",
|
||||
"latent_upscale_model": "latent_upscale_models",
|
||||
"latent_upscale_models": "latent_upscale_models",
|
||||
|
||||
@@ -11,33 +11,11 @@ from typing import Any, Dict, List, Optional
|
||||
from .contracts import ModelReference, Resolution, ResolvedModel
|
||||
from .custom_nodes import get_custom_node_resolution_metadata
|
||||
from .path_utils import get_filename_from_path
|
||||
from .type_utils import CATEGORY_MAP, normalize_category_token
|
||||
from .workflow import dynamic_widgets
|
||||
from .workflow.widgets import get_widget_name_candidates, normalize_widget_name
|
||||
from .workflow_updater import update_model_path
|
||||
|
||||
_CATEGORY_ALIASES = {
|
||||
"checkpoint": "checkpoints",
|
||||
"checkpoints": "checkpoints",
|
||||
"ckpt": "checkpoints",
|
||||
"lora": "loras",
|
||||
"loras": "loras",
|
||||
"text_encoder": "text_encoders",
|
||||
"text_encoders": "text_encoders",
|
||||
"clip": "text_encoders",
|
||||
"vae": "vae",
|
||||
"controlnet": "controlnet",
|
||||
"control_net": "controlnet",
|
||||
"upscale": "upscale_models",
|
||||
"upscaler": "upscale_models",
|
||||
"upscale_model": "upscale_models",
|
||||
"upscale_models": "upscale_models",
|
||||
"diffusion_model": "diffusion_models",
|
||||
"diffusion_models": "diffusion_models",
|
||||
"unet": "diffusion_models",
|
||||
"embedding": "embeddings",
|
||||
"embeddings": "embeddings",
|
||||
}
|
||||
|
||||
_LORA_MANAGER_NODE_TYPES = {
|
||||
"LoraLoaderV2",
|
||||
"Lora Loader (LoraManager)",
|
||||
@@ -64,10 +42,10 @@ _TRANSFER_ACTIVITY_SCOPES = {"all", "active", "inactive"}
|
||||
|
||||
def normalize_transfer_category(value: Any) -> str:
|
||||
"""Normalize the category names used by workflow and metadata payloads."""
|
||||
token = str(value or "").strip().lower().replace("-", "_")
|
||||
token = normalize_category_token(value)
|
||||
if not token or token in {"unknown", "none", "null"}:
|
||||
return ""
|
||||
return _CATEGORY_ALIASES.get(token, token)
|
||||
return CATEGORY_MAP.get(token, token)
|
||||
|
||||
|
||||
def _normalize_identity(value: Any) -> str:
|
||||
@@ -289,17 +267,6 @@ def _resolution_payload(resolution: Resolution) -> Dict[str, Any]:
|
||||
return payload
|
||||
|
||||
|
||||
def _assign_sources(
|
||||
sources: Sequence[Mapping[str, Any]],
|
||||
references: Sequence[ModelReference],
|
||||
) -> List[tuple[ModelReference, Mapping[str, Any]]]:
|
||||
if not sources or not references:
|
||||
return []
|
||||
if len(sources) == 1:
|
||||
return [(reference, sources[0]) for reference in references]
|
||||
return list(zip(references, sources, strict=False))
|
||||
|
||||
|
||||
def _select_source_for_reference(
|
||||
category_sources: Sequence[Mapping[str, Any]],
|
||||
selector: Mapping[str, Any],
|
||||
|
||||
Reference in New Issue
Block a user