Merge e93d5f9edabcd7879500a2135693d5394e920610 into bf2650a80e5a7a888da206eab45c53dbb22940f7

This commit is contained in:
someghuser 2024-11-28 20:59:25 +00:00 committed by GitHub
commit 45f4595d80
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 0 deletions

View File

@ -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):

View File

@ -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),