Fix ComfyUI generation for non-relative paths

This commit is contained in:
Cohee 2024-12-22 00:52:09 +02:00
parent d9101ce679
commit 713443d234
4 changed files with 22 additions and 19 deletions

10
package-lock.json generated
View File

@ -65,6 +65,7 @@
"simple-git": "^3.19.1",
"slidetoggle": "^4.0.0",
"tiktoken": "^1.0.16",
"url-join": "^5.0.0",
"vectra": "^0.2.2",
"wavefile": "^11.0.0",
"webpack": "^5.95.0",
@ -7053,6 +7054,15 @@
"punycode": "^2.1.0"
}
},
"node_modules/url-join": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/url-join/-/url-join-5.0.0.tgz",
"integrity": "sha512-n2huDr9h9yzd6exQVnH/jU5mr+Pfx08LRXXZhkLLetAMESRj+anQsTAh940iMrIetKAmry9coFuZQ2jY8/p3WA==",
"license": "MIT",
"engines": {
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
}
},
"node_modules/utf8-byte-length": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/utf8-byte-length/-/utf8-byte-length-1.0.4.tgz",

View File

@ -55,6 +55,7 @@
"simple-git": "^3.19.1",
"slidetoggle": "^4.0.0",
"tiktoken": "^1.0.16",
"url-join": "^5.0.0",
"vectra": "^0.2.2",
"wavefile": "^11.0.0",
"webpack": "^5.95.0",

View File

@ -1112,7 +1112,7 @@ function onHrSecondPassStepsInput() {
function onComfyUrlInput() {
// Remove trailing slashes
extension_settings.sd.comfy_url = String($('#sd_comfy_url').val() ?? '').replace(/\/$/, '');
extension_settings.sd.comfy_url = String($('#sd_comfy_url').val());
saveSettingsDebounced();
}

View File

@ -6,6 +6,7 @@ import fetch from 'node-fetch';
import sanitize from 'sanitize-filename';
import { sync as writeFileAtomicSync } from 'write-file-atomic';
import FormData from 'form-data';
import urlJoin from 'url-join';
import { delay, getBasicAuthHeader, tryParse } from '../util.js';
import { jsonParser } from '../express-common.js';
@ -364,8 +365,7 @@ const comfy = express.Router();
comfy.post('/ping', jsonParser, async (request, response) => {
try {
const url = new URL(request.body.url);
url.pathname += '/system_stats';
const url = new URL(urlJoin(request.body.url, '/system_stats'));
const result = await fetch(url);
if (!result.ok) {
@ -381,8 +381,7 @@ comfy.post('/ping', jsonParser, async (request, response) => {
comfy.post('/samplers', jsonParser, async (request, response) => {
try {
const url = new URL(request.body.url);
url.pathname += '/object_info';
const url = new URL(urlJoin(request.body.url, '/object_info'));
const result = await fetch(url);
if (!result.ok) {
@ -400,8 +399,7 @@ comfy.post('/samplers', jsonParser, async (request, response) => {
comfy.post('/models', jsonParser, async (request, response) => {
try {
const url = new URL(request.body.url);
url.pathname += '/object_info';
const url = new URL(urlJoin(request.body.url, '/object_info'));
const result = await fetch(url);
if (!result.ok) {
@ -429,8 +427,7 @@ comfy.post('/models', jsonParser, async (request, response) => {
comfy.post('/schedulers', jsonParser, async (request, response) => {
try {
const url = new URL(request.body.url);
url.pathname += '/object_info';
const url = new URL(urlJoin(request.body.url, '/object_info'));
const result = await fetch(url);
if (!result.ok) {
@ -448,8 +445,7 @@ comfy.post('/schedulers', jsonParser, async (request, response) => {
comfy.post('/vaes', jsonParser, async (request, response) => {
try {
const url = new URL(request.body.url);
url.pathname += '/object_info';
const url = new URL(urlJoin(request.body.url, '/object_info'));
const result = await fetch(url);
if (!result.ok) {
@ -516,15 +512,13 @@ comfy.post('/delete-workflow', jsonParser, async (request, response) => {
comfy.post('/generate', jsonParser, async (request, response) => {
try {
const url = new URL(request.body.url);
url.pathname += '/prompt';
const url = new URL(urlJoin(request.body.url, '/prompt'));
const controller = new AbortController();
request.socket.removeAllListeners('close');
request.socket.on('close', function () {
if (!response.writableEnded && !item) {
const interruptUrl = new URL(request.body.url);
interruptUrl.pathname += '/interrupt';
const interruptUrl = new URL(urlJoin(request.body.url, '/interrupt'));
fetch(interruptUrl, { method: 'POST', headers: { 'Authorization': getBasicAuthHeader(request.body.auth) } });
}
controller.abort();
@ -543,8 +537,7 @@ comfy.post('/generate', jsonParser, async (request, response) => {
const data = await promptResult.json();
const id = data.prompt_id;
let item;
const historyUrl = new URL(request.body.url);
historyUrl.pathname += '/history';
const historyUrl = new URL(urlJoin(request.body.url, '/history'));
while (true) {
const result = await fetch(historyUrl);
if (!result.ok) {
@ -568,8 +561,7 @@ comfy.post('/generate', jsonParser, async (request, response) => {
throw new Error(`ComfyUI generation did not succeed.\n\n${errorMessages}`.trim());
}
const imgInfo = Object.keys(item.outputs).map(it => item.outputs[it].images).flat()[0];
const imgUrl = new URL(request.body.url);
imgUrl.pathname += '/view';
const imgUrl = new URL(urlJoin(request.body.url, '/view'));
imgUrl.search = `?filename=${imgInfo.filename}&subfolder=${imgInfo.subfolder}&type=${imgInfo.type}`;
const imgResponse = await fetch(imgUrl);
if (!imgResponse.ok) {