From ba9b4b8bd4f6a33b3da4e34f20fc377692769734 Mon Sep 17 00:00:00 2001 From: Karl Date: Thu, 10 Jul 2025 16:24:57 +0100 Subject: [PATCH] fix(favorites): preserve favorite status after image rename Previously, if a user favorited a newly generated image (named 'image.png'), the favorite status would be lost once the image was automatically renamed to its final timestamped filename. This change modifies the renaming logic to check the `favourites.json` file. If 'image.png' is found, its entry is updated with the new filename, ensuring the favorite status is preserved. --- libs/generic.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libs/generic.py b/libs/generic.py index fed2e33..299528c 100644 --- a/libs/generic.py +++ b/libs/generic.py @@ -51,10 +51,22 @@ def load_config() -> configparser.ConfigParser: def rename_image() -> str | None: """Renames 'image.png' in the output folder to a timestamped filename if it exists.""" old_path = os.path.join(user_config["comfyui"]["output_dir"], "image.png") + favourites_file = "./favourites.json" if os.path.exists(old_path): new_filename = f"{str(time.time())}.png" new_path = os.path.join(user_config["comfyui"]["output_dir"], new_filename) + + # Check if image.png is a favourite + if os.path.exists(favourites_file): + with open(favourites_file, 'r') as f: + favourites = json.load(f) + if "image.png" in favourites: + favourites.remove("image.png") + favourites.append(new_filename) + with open(favourites_file, 'w') as f: + json.dump(favourites, f) + os.rename(old_path, new_path) generate_thumbnail(new_path) print(f"Renamed 'image.png' to '{new_filename}'")