Browse Source

Allow extensions to add custom css

pull/1639/head
huchenlei 1 year ago
parent
commit
b06527ba23
  1. 5
      server.py
  2. 9
      web/scripts/api.js
  3. 9
      web/scripts/app.js

5
server.py

@ -143,6 +143,11 @@ class PromptServer():
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:
dir_type = "input"

9
web/scripts/api.js

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

9
web/scripts/app.js

@ -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);
}
/**

Loading…
Cancel
Save