preview
This commit is contained in:
parent
927577c201
commit
e29085c314
@ -24,6 +24,7 @@ const Txt23DHandler: RequestHandler<Txt2ImgRequest, any> = async (ctx) => {
|
|||||||
url: ctx.body = baseUrl + '/view?filename=' + await new Promise((resolve, reject) => {
|
url: ctx.body = baseUrl + '/view?filename=' + await new Promise((resolve, reject) => {
|
||||||
const taskID = Math.random().toFixed(10);
|
const taskID = Math.random().toFixed(10);
|
||||||
const ws = new WebSocket(`${baseWsUrl}/ws?clientId=${taskID}`);
|
const ws = new WebSocket(`${baseWsUrl}/ws?clientId=${taskID}`);
|
||||||
|
ws.binaryType = "arraybuffer";
|
||||||
ws.onopen = () => {
|
ws.onopen = () => {
|
||||||
try {
|
try {
|
||||||
axios.post("/prompt", {
|
axios.post("/prompt", {
|
||||||
|
@ -21,6 +21,7 @@ const Txt2ImgHandler: RequestHandler<Txt2ImgRequest, any> = async (ctx, next) =>
|
|||||||
const { prompt, loraDetail, loraModel } = requestBody;
|
const { prompt, loraDetail, loraModel } = requestBody;
|
||||||
const inputNode = selectNodeFromApiJSONbyID(txt2imgAPIformatJSON, "33");
|
const inputNode = selectNodeFromApiJSONbyID(txt2imgAPIformatJSON, "33");
|
||||||
let temp = "";
|
let temp = "";
|
||||||
|
let preViewBlobs:any = [];
|
||||||
inputNode.inputs.string = prompt;
|
inputNode.inputs.string = prompt;
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
data: await new Promise((resolve, reject) => {
|
data: await new Promise((resolve, reject) => {
|
||||||
@ -33,6 +34,7 @@ const Txt2ImgHandler: RequestHandler<Txt2ImgRequest, any> = async (ctx, next) =>
|
|||||||
prompt: txt2imgAPIformatJSON,
|
prompt: txt2imgAPIformatJSON,
|
||||||
// extra_data: txt2imgAPIformatExtraData
|
// extra_data: txt2imgAPIformatExtraData
|
||||||
});
|
});
|
||||||
|
console.log(`ok`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
}
|
}
|
||||||
@ -50,11 +52,13 @@ const Txt2ImgHandler: RequestHandler<Txt2ImgRequest, any> = async (ctx, next) =>
|
|||||||
temp = data.output.text[0];
|
temp = data.output.text[0];
|
||||||
}
|
}
|
||||||
if (data.node === '94') {
|
if (data.node === '94') {
|
||||||
resolve({ prompt: temp, url: baseUrl + '/view?filename=' + data.output.images[0].filename })
|
resolve({ prompt: temp, url: baseUrl + '/view?filename=' + data.output.images[0].filename, preViewBlobs: preViewBlobs });
|
||||||
}
|
}
|
||||||
|
}else if (type === "executing") {
|
||||||
}
|
}
|
||||||
} else {
|
} else if (event.data instanceof Buffer) {
|
||||||
|
console.log(`event.data`, event.data);
|
||||||
|
preViewBlobs.push(event.data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,8 +44,11 @@ const UpscaleHandler: RequestHandler<any ,any> = async (ctx) => {
|
|||||||
resolve(data.output.images[0].filename)
|
resolve(data.output.images[0].filename)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else if(event.data instanceof ArrayBuffer) {
|
||||||
|
const blob = new Blob([event.data])// arraybuffer to blob
|
||||||
|
let a = new FileReader();
|
||||||
|
a.onload = function (e) { console.log('image/png;base64,'+ e.target!.result) }
|
||||||
|
a.readAsDataURL(blob);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
86
test.html
Normal file
86
test.html
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<title>测试页面</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<h1>测试页面</h1>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
|
<script>
|
||||||
|
import {
|
||||||
|
app
|
||||||
|
} from "../../scripts/app.js";
|
||||||
|
import {
|
||||||
|
api
|
||||||
|
} from "../../scripts/api.js";
|
||||||
|
|
||||||
|
app.registerExtension({
|
||||||
|
name: "efficiency.previewfix",
|
||||||
|
lastExecutedNodeId: null,
|
||||||
|
blobsToRevoke: [], // Array to accumulate blob URLs for revocation
|
||||||
|
debug: false,
|
||||||
|
|
||||||
|
log(...args) {
|
||||||
|
if (this.debug) console.log(...args);
|
||||||
|
},
|
||||||
|
|
||||||
|
error(...args) {
|
||||||
|
if (this.debug) console.error(...args);
|
||||||
|
},
|
||||||
|
|
||||||
|
shouldRevokeBlobForNode(nodeId) {
|
||||||
|
const node = app.graph.getNodeById(nodeId);
|
||||||
|
|
||||||
|
const validTitles = [
|
||||||
|
"KSampler (Efficient)",
|
||||||
|
"KSampler Adv. (Efficient)",
|
||||||
|
"KSampler SDXL (Eff.)"
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!node || !validTitles.includes(node.title)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const getValue = name => ((node.widgets || []).find(w => w.name === name) || {}).value;
|
||||||
|
return getValue("preview_method") !== "none" && getValue("vae_decode").includes("true");
|
||||||
|
},
|
||||||
|
|
||||||
|
setup() {
|
||||||
|
// Intercepting blob creation to store and immediately revoke the last blob URL
|
||||||
|
const originalCreateObjectURL = URL.createObjectURL;
|
||||||
|
URL.createObjectURL = (object) => {
|
||||||
|
const blobURL = originalCreateObjectURL(object);
|
||||||
|
if (blobURL.startsWith('blob:')) {
|
||||||
|
this.log("[BlobURLLogger] Blob URL created:", blobURL);
|
||||||
|
|
||||||
|
// If the current node meets the criteria, add the blob URL to the revocation list
|
||||||
|
if (this.shouldRevokeBlobForNode(this.lastExecutedNodeId)) {
|
||||||
|
this.blobsToRevoke.push(blobURL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return blobURL;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Listen to the start of the node execution to revoke all accumulated blob URLs
|
||||||
|
api.addEventListener("executing", ({
|
||||||
|
detail
|
||||||
|
}) => {
|
||||||
|
if (this.lastExecutedNodeId !== detail || detail === null) {
|
||||||
|
this.blobsToRevoke.forEach(blob => {
|
||||||
|
this.log("[BlobURLLogger] Revoking Blob URL:", blob);
|
||||||
|
URL.revokeObjectURL(blob);
|
||||||
|
});
|
||||||
|
this.blobsToRevoke = []; // Clear the list after revoking all blobs
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the last executed node ID
|
||||||
|
this.lastExecutedNodeId = detail;
|
||||||
|
});
|
||||||
|
|
||||||
|
this.log("[BlobURLLogger] Hook attached.");
|
||||||
|
},
|
||||||
|
});
|
||||||
|
</script>
|
Loading…
x
Reference in New Issue
Block a user