From cbf862eba5068af2380cfe3c2d10aad040d1fd89 Mon Sep 17 00:00:00 2001 From: relhamdi Date: Wed, 3 Jun 2026 11:05:28 +0200 Subject: [PATCH] Move get assets and load functions --- src/nodes/style_loader.py | 60 +++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/src/nodes/style_loader.py b/src/nodes/style_loader.py index be229a6..923012b 100644 --- a/src/nodes/style_loader.py +++ b/src/nodes/style_loader.py @@ -209,6 +209,36 @@ class StyleLoader: # --- API Routes --- +@PromptServer.instance.routes.get(f"{BASE_ENDPOINT}/assets") +async def get_assets(request: web.Request) -> web.Response: + return web.json_response( + { + "checkpoints": folder_paths.get_filename_list("checkpoints"), + "vae": folder_paths.get_filename_list("vae"), + "loras": folder_paths.get_filename_list("loras"), + "samplers": SAMPLER_NAMES, + "schedulers": SCHEDULER_NAMES, + } + ) + + +@PromptServer.instance.routes.get(f"{BASE_ENDPOINT}/load") +async def load_style_content(request: web.Request) -> web.Response: + file = request.rel_url.query.get("file", "") + rel = safe_relative_path(file) + if not rel: + return web.json_response({"error": "Invalid file path."}, status=400) + try: + data = load_json_file(STYLES_DIR, rel) + content = json.dumps(data, indent=2, ensure_ascii=False) + + return web.json_response({"content": content}) + except FileNotFoundError: + return web.json_response({"error": "File not found."}, status=404) + except Exception as e: + return web.json_response({"error": str(e)}, status=500) + + @PromptServer.instance.routes.post(f"{BASE_ENDPOINT}/save") async def save_style(request: web.Request) -> web.Response: try: @@ -279,36 +309,6 @@ async def delete_style(request: web.Request) -> web.Response: return web.json_response({"error": str(e)}, status=500) -@PromptServer.instance.routes.get(f"{BASE_ENDPOINT}/assets") -async def get_assets(request: web.Request) -> web.Response: - return web.json_response( - { - "checkpoints": folder_paths.get_filename_list("checkpoints"), - "vae": folder_paths.get_filename_list("vae"), - "loras": folder_paths.get_filename_list("loras"), - "samplers": SAMPLER_NAMES, - "schedulers": SCHEDULER_NAMES, - } - ) - - -@PromptServer.instance.routes.get(f"{BASE_ENDPOINT}/load") -async def load_style_content(request: web.Request) -> web.Response: - file = request.rel_url.query.get("file", "") - rel = safe_relative_path(file) - if not rel: - return web.json_response({"error": "Invalid file path."}, status=400) - try: - data = load_json_file(STYLES_DIR, rel) - content = json.dumps(data, indent=2, ensure_ascii=False) - - return web.json_response({"content": content}) - except FileNotFoundError: - return web.json_response({"error": "File not found."}, status=404) - except Exception as e: - return web.json_response({"error": str(e)}, status=500) - - # --- Registration --- NODE_CLASS_MAPPINGS = {