fix(civitai): improve metadata parsing for nested structures, see #700

- Refactor metadata detection to handle nested "meta" objects
- Add support for lowercase "lora:" hash keys
- Extract metadata from nested "meta" field when present
- Update tests to verify nested metadata parsing
- Handle case-insensitive LORA hash detection

The changes ensure proper parsing of Civitai image metadata that may be wrapped in nested structures, improving compatibility with different API response formats.
This commit is contained in:
Will Miao
2025-11-26 13:46:08 +08:00
parent 5d4917c8d9
commit f8b9fa9b20
3 changed files with 97 additions and 9 deletions

View File

@@ -107,6 +107,12 @@ class RecipeAnalysisService:
raise RecipeDownloadError("No image URL found in Civitai response")
await self._download_image(image_url, temp_path)
metadata = image_info.get("meta") if "meta" in image_info else None
if (
isinstance(metadata, dict)
and "meta" in metadata
and isinstance(metadata["meta"], dict)
):
metadata = metadata["meta"]
else:
await self._download_image(url, temp_path)