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

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

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