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] serve css from custom_nodes styles directories --- server.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/server.py b/server.py index 1a8e92b8..28ca223e 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),