feat(civitai): expand image metadata detection criteria, see #700

Add additional CivitAI image metadata fields to detection logic including generation parameters (prompt, steps, sampler, etc.) and model information. Also improve LoRA hash detection by checking both main metadata and nested meta objects. This ensures more comprehensive identification of CivitAI image metadata across different response formats.
This commit is contained in:
Will Miao
2025-11-27 10:28:04 +08:00
parent f8b9fa9b20
commit ecb512995c

View File

@@ -25,27 +25,41 @@ class CivitaiApiMetadataParser(RecipeMetadataParser):
return False return False
def has_markers(payload: Dict[str, Any]) -> bool: def has_markers(payload: Dict[str, Any]) -> bool:
return any( # Check for common CivitAI image metadata fields
key in payload civitai_image_fields = (
for key in ( "resources",
"resources", "civitaiResources",
"civitaiResources", "additionalResources",
"additionalResources", "hashes",
) "prompt",
"negativePrompt",
"steps",
"sampler",
"cfgScale",
"seed",
"width",
"height",
"Model",
"Model hash"
) )
return any(key in payload for key in civitai_image_fields)
# Check the main metadata object
if has_markers(metadata): if has_markers(metadata):
return True return True
# Check for LoRA hash patterns
hashes = metadata.get("hashes") hashes = metadata.get("hashes")
if isinstance(hashes, dict) and any(str(key).lower().startswith("lora:") for key in hashes): if isinstance(hashes, dict) and any(str(key).lower().startswith("lora:") for key in hashes):
return True return True
# Check nested meta object (common in CivitAI image responses)
nested_meta = metadata.get("meta") nested_meta = metadata.get("meta")
if isinstance(nested_meta, dict): if isinstance(nested_meta, dict):
if has_markers(nested_meta): if has_markers(nested_meta):
return True return True
# Also check for LoRA hash patterns in nested meta
hashes = nested_meta.get("hashes") hashes = nested_meta.get("hashes")
if isinstance(hashes, dict) and any(str(key).lower().startswith("lora:") for key in hashes): if isinstance(hashes, dict) and any(str(key).lower().startswith("lora:") for key in hashes):
return True return True