From 8bee8f406988c0df616da5de6d8c54e235423a79 Mon Sep 17 00:00:00 2001 From: Will Miao Date: Sat, 4 Jul 2026 18:40:34 +0800 Subject: [PATCH] fix(recipe): fallback to locate custom example image on disk by model hash and image id (#1012) --- py/routes/handlers/recipe_handlers.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/py/routes/handlers/recipe_handlers.py b/py/routes/handlers/recipe_handlers.py index 2f1fa4f8..24fe47fe 100644 --- a/py/routes/handlers/recipe_handlers.py +++ b/py/routes/handlers/recipe_handlers.py @@ -2218,6 +2218,31 @@ class RecipeManagementHandler: "Failed to download image for recipe: %s", exc ) + # Fallback: try to locate a custom image on disk using model_hash + image id + if image_bytes is None: + image_id = image_data.get("id") or "" + if image_id and model_hash: + from ...utils.example_images_paths import get_model_folder + model_folder = get_model_folder(model_hash) + if model_folder and os.path.exists(model_folder): + for fname in os.listdir(model_folder): + if f"custom_{image_id}" in fname: + ext = os.path.splitext(fname)[1].lower() + if ext not in (".jpg", ".jpeg", ".png", ".webp", ".gif"): + continue + fpath = os.path.join(model_folder, fname) + if os.path.isfile(fpath): + try: + with open(fpath, "rb") as f: + image_bytes = f.read() + extension = ext + except Exception as exc: + self._logger.warning( + "Failed to read custom image file %s: %s", + fpath, exc, + ) + break + prompt = ( (parsed.get("gen_params") or {}).get("prompt") or "" )