Allow extensions to add custom css

This commit is contained in:
huchenlei 2023-09-29 22:52:41 -04:00
parent 213976f8c3
commit b06527ba23
3 changed files with 23 additions and 0 deletions

View File

@ -142,6 +142,11 @@ class PromptServer():
name) + "/" + os.path.relpath(f, dir).replace("\\", "/"), files)))
return web.json_response(extensions)
@routes.get("/extensions/styles")
async def get_extensions_styles(request):
files = glob.glob(os.path.join(self.web_root, 'extensions/**/*.css'), recursive=True)
return web.json_response(list(map(lambda f: "/" + os.path.relpath(f, self.web_root).replace("\\", "/"), files)))
def get_dir_by_type(dir_type):
if dir_type is None:

View File

@ -163,6 +163,15 @@ class ComfyApi extends EventTarget {
return await resp.json();
}
/**
* Gets a list of extension's CSS style urls
* @returns An array of CSS urls to include
*/
async getExtensionsStyles() {
const resp = await this.fetchApi("/extensions/styles", { cache: "no-store" });
return await resp.json();
}
/**
* Gets a list of embedding names
* @returns An array of script urls to import

View File

@ -1130,6 +1130,15 @@ export class ComfyApp {
});
await Promise.all(extensionPromises);
const styles = await api.getExtensionsStyles();
function loadCSS(url) {
var link = document.createElement('link');
link.rel = 'stylesheet';
link.href = url;
document.head.appendChild(link);
}
styles.forEach(loadCSS);
}
/**