From f23bd87e47d5be8ddd60a61cff127c4ed269d5d8 Mon Sep 17 00:00:00 2001 From: someghuser <141381806+someghuser@users.noreply.github.com> Date: Tue, 28 Nov 2023 23:46:01 +0800 Subject: [PATCH 1/2] Update nodes.py allow custom_nodes to set a styles directory for css --- nodes.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/nodes.py b/nodes.py index df40f8094..ce090f401 100644 --- a/nodes.py +++ b/nodes.py @@ -1779,6 +1779,7 @@ NODE_DISPLAY_NAME_MAPPINGS = { } EXTENSION_WEB_DIRS = {} +EXTENSION_STYLE_DIRS = {} def load_custom_node(module_path, ignore=set()): module_name = os.path.basename(module_path) @@ -1797,6 +1798,11 @@ def load_custom_node(module_path, ignore=set()): 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): From e93d5f9edabcd7879500a2135693d5394e920610 Mon Sep 17 00:00:00 2001 From: someghuser <141381806+someghuser@users.noreply.github.com> Date: Tue, 28 Nov 2023 23:46:50 +0800 Subject: [PATCH 2/2] serve css from custom_nodes styles directories --- server.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/server.py b/server.py index 1a8e92b8f..28ca223e9 100644 --- a/server.py +++ b/server.py @@ -130,6 +130,16 @@ class PromptServer(): embeddings = folder_paths.get_filename_list("embeddings") return web.json_response(list(map(lambda a: os.path.splitext(a)[0], embeddings))) + @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( @@ -523,6 +533,11 @@ class PromptServer(): def add_routes(self): 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, follow_symlinks=True),