add GET /workflow_templates

This commit is contained in:
bezo97 2024-12-23 20:15:51 +01:00
parent f18ebbd316
commit b6e3bc2451
2 changed files with 15 additions and 4 deletions

View File

@ -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]] = {}

View File

@ -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: