support more example folders

This commit is contained in:
Terry Jia 2025-04-27 08:34:59 -04:00
parent c8cd7ad795
commit d5b9b0bc6c

View File

@ -93,16 +93,20 @@ class CustomNodeManager:
def add_routes(self, routes, webapp, loadedModules): def add_routes(self, routes, webapp, loadedModules):
example_workflow_folder_names = ["example_workflows", "example", "examples", "workflow", "workflows"]
@routes.get("/workflow_templates") @routes.get("/workflow_templates")
async def get_workflow_templates(request): async def get_workflow_templates(request):
"""Returns a web response that contains the map of custom_nodes names and their associated workflow templates. The ones without templates are omitted.""" """Returns a web response that contains the map of custom_nodes names and their associated workflow templates. The ones without templates are omitted."""
files = [
file files = []
for folder in folder_paths.get_folder_paths("custom_nodes")
for file in glob.glob( for folder in folder_paths.get_folder_paths("custom_nodes"):
os.path.join(folder, "*/example_workflows/*.json") for folder_name in example_workflow_folder_names:
) pattern = os.path.join(folder, f"*/{folder_name}/*.json")
] matched_files = glob.glob(pattern)
files.extend(matched_files)
workflow_templates_dict = ( workflow_templates_dict = (
{} {}
) # custom_nodes folder name -> example workflow names ) # custom_nodes folder name -> example workflow names
@ -118,15 +122,17 @@ class CustomNodeManager:
# Serve workflow templates from custom nodes. # Serve workflow templates from custom nodes.
for module_name, module_dir in loadedModules: for module_name, module_dir in loadedModules:
workflows_dir = os.path.join(module_dir, "example_workflows") for folder_name in example_workflow_folder_names:
if os.path.exists(workflows_dir): workflows_dir = os.path.join(module_dir, folder_name)
webapp.add_routes(
[ if os.path.exists(workflows_dir):
web.static( webapp.add_routes(
"/api/workflow_templates/" + module_name, workflows_dir [
) web.static(
] "/api/workflow_templates/" + module_name, workflows_dir
) )
]
)
@routes.get("/i18n") @routes.get("/i18n")
async def get_i18n(request): async def get_i18n(request):