Super hacky

Load all the remote JS files in the most unconventional way to work locally.  Still not perfect.  Most of the interface and custom nodes can load, but it's obviously still broken.  The next way I'll go about this is a hack to have local versions of the custom nodes and during setup import from local... Or, create a script to download and save the files locally from remote before local startup
This commit is contained in:
Andre Molnar 2023-12-01 22:31:21 -05:00
parent 86bcd911a4
commit d25af394ec
2 changed files with 2584 additions and 2333 deletions

View File

@ -4,11 +4,12 @@ class ComfyApi extends EventTarget {
constructor() { constructor() {
super(); super();
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("/");
} }
set apiBase(apiBase) { set apiBase(apiBase) {
this.api_base = apiBase; this.api_base = apiBase;
this.api_host = this.api_base.replace(/^(https?:|)\/\//, "");
} }
apiURL(route) { apiURL(route) {
@ -54,7 +55,9 @@ class ComfyApi extends EventTarget {
existingSession = "?clientId=" + existingSession; existingSession = "?clientId=" + existingSession;
} }
this.socket = new WebSocket( this.socket = new WebSocket(
`ws${window.location.protocol === "https:" ? "s" : ""}://${this.api_host}${this.api_base}/ws${existingSession}` `ws${window.location.protocol === "https:" ? "s" : ""}://${
this.api_host
}/ws${existingSession}`
); );
this.socket.binaryType = "arraybuffer"; this.socket.binaryType = "arraybuffer";
@ -92,24 +95,29 @@ class ComfyApi extends EventTarget {
switch (eventType) { switch (eventType) {
case 1: case 1:
const view2 = new DataView(event.data); const view2 = new DataView(event.data);
const imageType = view2.getUint32(0) const imageType = view2.getUint32(0);
let imageMime let imageMime;
switch (imageType) { switch (imageType) {
case 1: case 1:
default: default:
imageMime = "image/jpeg"; imageMime = "image/jpeg";
break; break;
case 2: case 2:
imageMime = "image/png" imageMime = "image/png";
} }
const imageBlob = new Blob([buffer.slice(4)], { type: imageMime }); const imageBlob = new Blob([buffer.slice(4)], {
this.dispatchEvent(new CustomEvent("b_preview", { detail: imageBlob })); type: imageMime,
});
this.dispatchEvent(
new CustomEvent("b_preview", { detail: imageBlob })
);
break; break;
default: default:
throw new Error(`Unknown binary websocket message of type ${eventType}`); throw new Error(
`Unknown binary websocket message of type ${eventType}`
);
} }
} } else {
else {
const msg = JSON.parse(event.data); const msg = JSON.parse(event.data);
switch (msg.type) { switch (msg.type) {
case "status": case "status":
@ -117,29 +125,45 @@ class ComfyApi extends EventTarget {
this.clientId = msg.data.sid; this.clientId = msg.data.sid;
window.name = this.clientId; window.name = this.clientId;
} }
this.dispatchEvent(new CustomEvent("status", { detail: msg.data.status })); this.dispatchEvent(
new CustomEvent("status", { detail: msg.data.status })
);
break; break;
case "progress": case "progress":
this.dispatchEvent(new CustomEvent("progress", { detail: msg.data })); this.dispatchEvent(
new CustomEvent("progress", { detail: msg.data })
);
break; break;
case "executing": case "executing":
this.dispatchEvent(new CustomEvent("executing", { detail: msg.data.node })); this.dispatchEvent(
new CustomEvent("executing", { detail: msg.data.node })
);
break; break;
case "executed": case "executed":
this.dispatchEvent(new CustomEvent("executed", { detail: msg.data })); this.dispatchEvent(
new CustomEvent("executed", { detail: msg.data })
);
break; break;
case "execution_start": case "execution_start":
this.dispatchEvent(new CustomEvent("execution_start", { detail: msg.data })); this.dispatchEvent(
new CustomEvent("execution_start", { detail: msg.data })
);
break; break;
case "execution_error": case "execution_error":
this.dispatchEvent(new CustomEvent("execution_error", { detail: msg.data })); this.dispatchEvent(
new CustomEvent("execution_error", { detail: msg.data })
);
break; break;
case "execution_cached": case "execution_cached":
this.dispatchEvent(new CustomEvent("execution_cached", { detail: msg.data })); this.dispatchEvent(
new CustomEvent("execution_cached", { detail: msg.data })
);
break; break;
default: default:
if (this.#registered.has(msg.type)) { if (this.#registered.has(msg.type)) {
this.dispatchEvent(new CustomEvent(msg.type, { detail: msg.data })); this.dispatchEvent(
new CustomEvent(msg.type, { detail: msg.data })
);
} else { } else {
throw new Error(`Unknown message type ${msg.type}`); throw new Error(`Unknown message type ${msg.type}`);
} }

File diff suppressed because it is too large Load Diff