cleanup api.js code

This commit is contained in:
Weixuan Fu 2024-07-19 12:44:18 +08:00
parent c3e56dde28
commit b73636613a

View File

@ -6,14 +6,8 @@ export class ComfyApi extends EventTarget {
this.api_host = location.host; this.api_host = location.host;
this.api_base = location.pathname.split('/').slice(0, -1).join('/'); this.api_base = location.pathname.split('/').slice(0, -1).join('/');
this.initialClientId = sessionStorage.getItem("clientId"); this.initialClientId = sessionStorage.getItem("clientId");
this.clientId = this.initialClientId ?? this.generateSimpleUID();
sessionStorage.setItem("clientId", this.clientId);
} }
generateSimpleUID() {
return Math.random().toString(36).slice(2,10);
}
apiURL(route) { apiURL(route) {
return this.api_base + route; return this.api_base + route;
} }
@ -580,6 +574,14 @@ export class ServerlessComfyApi extends ComfyApi {
return await res.json(); return await res.json();
} }
generateSimpleUID() {
return Math.random().toString(36).slice(2,10);
}
async init() {
this.clientId = this.initialClientId ?? this.generateSimpleUID();
sessionStorage.setItem("clientId", this.clientId);
}
async getExtensions() { async getExtensions() {
const COMFYUI_CORE_EXTENSIONS = [ const COMFYUI_CORE_EXTENSIONS = [
"/extensions/core/clipspace.js", "/extensions/core/clipspace.js",