diff --git a/nodes.py b/nodes.py index 3a68d43ce..400d26687 100644 --- a/nodes.py +++ b/nodes.py @@ -1984,6 +1984,7 @@ NODE_DISPLAY_NAME_MAPPINGS = { } EXTENSION_WEB_DIRS = {} +EXTENSION_STYLE_DIRS = {} def get_module_name(module_path: str) -> str: @@ -2026,6 +2027,11 @@ def load_custom_node(module_path: str, ignore=set(), module_parent="custom_nodes sys.modules[module_name] = module module_spec.loader.exec_module(module) + if hasattr(module, "STYLE_DIRECTORY") and getattr(module, "STYLE_DIRECTORY") is not None: + style_dir = os.path.abspath(os.path.join(module_dir, getattr(module, "STYLE_DIRECTORY"))) + if os.path.isdir(style_dir): + EXTENSION_STYLE_DIRS[module_name] = style_dir + if hasattr(module, "WEB_DIRECTORY") and getattr(module, "WEB_DIRECTORY") is not None: web_dir = os.path.abspath(os.path.join(module_dir, getattr(module, "WEB_DIRECTORY"))) if os.path.isdir(web_dir): diff --git a/server.py b/server.py index 5e86558d4..cae780e3e 100644 --- a/server.py +++ b/server.py @@ -235,6 +235,16 @@ class PromptServer(): files = folder_paths.get_filename_list(folder) return web.json_response(files) + @routes.get("/styles") + async def get_styles(request): + styles = list() + for name, dir in nodes.EXTENSION_STYLE_DIRS.items(): + files = glob.glob(os.path.join(glob.escape(dir), '**/*.css'), recursive=True) + styles.extend(list(map(lambda f: "/styles/" + urllib.parse.quote( + name) + "/" + os.path.relpath(f, dir).replace("\\", "/"), files))) + + return web.json_response(styles) + @routes.get("/extensions") async def get_extensions(request): files = glob.glob(os.path.join( @@ -698,6 +708,11 @@ class PromptServer(): self.app.add_routes(api_routes) self.app.add_routes(self.routes) + for name, dir in nodes.EXTENSION_STYLE_DIRS.items(): + self.app.add_routes([ + web.static('/styles/' + urllib.parse.quote(name), dir, follow_symlinks=True), + ]) + for name, dir in nodes.EXTENSION_WEB_DIRS.items(): self.app.add_routes([ web.static('/extensions/' + urllib.parse.quote(name), dir),