mirror of
https://github.com/karl0ss/ai_image_frame_server.git
synced 2025-07-13 17:36:07 +01:00
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.
This commit is contained in:
parent
7f78912829
commit
ba9b4b8bd4
@ -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}'")
|
||||
|
Loading…
x
Reference in New Issue
Block a user