From b6e3bc2451641ef389c4d6c48497ed9fb0cd9d53 Mon Sep 17 00:00:00 2001 From: bezo97 Date: Mon, 23 Dec 2024 20:15:51 +0100 Subject: [PATCH] add GET /workflow_templates --- folder_paths.py | 9 +++++---- server.py | 10 ++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/folder_paths.py b/folder_paths.py index 61de51202..8494080a9 100644 --- a/folder_paths.py +++ b/folder_paths.py @@ -39,10 +39,11 @@ folder_names_and_paths["photomaker"] = ([os.path.join(models_dir, "photomaker")] folder_names_and_paths["classifiers"] = ([os.path.join(models_dir, "classifiers")], {""}) -output_directory = os.path.join(os.path.dirname(os.path.realpath(__file__)), "output") -temp_directory = os.path.join(os.path.dirname(os.path.realpath(__file__)), "temp") -input_directory = os.path.join(os.path.dirname(os.path.realpath(__file__)), "input") -user_directory = os.path.join(os.path.dirname(os.path.realpath(__file__)), "user") +output_directory = os.path.join(base_path, "output") +temp_directory = os.path.join(base_path, "temp") +input_directory = os.path.join(base_path, "input") +user_directory = os.path.join(base_path, "user") +custom_nodes_directory = os.path.join(base_path, "custom_nodes") filename_list_cache: dict[str, tuple[list[str], dict[str, float], float]] = {} diff --git a/server.py b/server.py index 22525507a..d0238f618 100644 --- a/server.py +++ b/server.py @@ -250,6 +250,16 @@ class PromptServer(): name) + "/" + os.path.relpath(f, dir).replace("\\", "/"), files))) return web.json_response(extensions) + + @routes.get("/workflow_templates") + async def get_workflow_templates(request): + files = glob.glob(os.path.join(folder_paths.custom_nodes_directory, '*/example_workflows/*.json')) + workflow_templates_dict = {} # custom_nodes folder name -> example workflow names + for file in files: + custom_nodes_name = os.path.basename(os.path.dirname(os.path.dirname(file))) + workflow_name = os.path.splitext(os.path.basename(file))[0] + workflow_templates_dict.setdefault(custom_nodes_name, []).append(workflow_name) + return web.json_response(workflow_templates_dict) def get_dir_by_type(dir_type): if dir_type is None: