serve css from custom_nodes styles directories

This commit is contained in:
someghuser 2023-11-28 23:46:50 +08:00 committed by GitHub
parent f23bd87e47
commit e93d5f9eda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 0 deletions

View File

@ -130,6 +130,16 @@ class PromptServer():
embeddings = folder_paths.get_filename_list("embeddings") embeddings = folder_paths.get_filename_list("embeddings")
return web.json_response(list(map(lambda a: os.path.splitext(a)[0], 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") @routes.get("/extensions")
async def get_extensions(request): async def get_extensions(request):
files = glob.glob(os.path.join( files = glob.glob(os.path.join(
@ -523,6 +533,11 @@ class PromptServer():
def add_routes(self): def add_routes(self):
self.app.add_routes(self.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(): for name, dir in nodes.EXTENSION_WEB_DIRS.items():
self.app.add_routes([ self.app.add_routes([
web.static('/extensions/' + urllib.parse.quote(name), dir, follow_symlinks=True), web.static('/extensions/' + urllib.parse.quote(name), dir, follow_symlinks=True),