Support ComfyUI hosted on relative URLs Closes #3208
| @@ -1111,7 +1111,8 @@ function onHrSecondPassStepsInput() { | ||
| 1111 | 1111 | } |
| 1112 | 1112 | |
| 1113 | 1113 | function onComfyUrlInput() { |
| 1114 | - extension_settings.sd.comfy_url = $('#sd_comfy_url').val(); | |
| 1114 | + // Remove trailing slashes | |
| 1115 | + extension_settings.sd.comfy_url = String($('#sd_comfy_url').val() ?? '').replace(/\/$/, ''); | |
| 1115 | 1116 | saveSettingsDebounced(); |
| 1116 | 1117 | } |
| 1117 | 1118 | |
| @@ -365,7 +365,7 @@ const comfy = express.Router(); | ||
| 365 | 365 | comfy.post('/ping', jsonParser, async (request, response) => { |
| 366 | 366 | try { |
| 367 | 367 | const url = new URL(request.body.url); |
| 368 | 368 | url.pathname += '/system_stats'; |
| 369 | 369 | |
| 370 | 370 | const result = await fetch(url); |
| 371 | 371 | if (!result.ok) { |
| @@ -382,7 +382,7 @@ comfy.post('/ping', jsonParser, async (request, response) => { | ||
| 382 | 382 | comfy.post('/samplers', jsonParser, async (request, response) => { |
| 383 | 383 | try { |
| 384 | 384 | const url = new URL(request.body.url); |
| 385 | 385 | url.pathname += '/object_info'; |
| 386 | 386 | |
| 387 | 387 | const result = await fetch(url); |
| 388 | 388 | if (!result.ok) { |
| @@ -401,7 +401,7 @@ comfy.post('/samplers', jsonParser, async (request, response) => { | ||
| 401 | 401 | comfy.post('/models', jsonParser, async (request, response) => { |
| 402 | 402 | try { |
| 403 | 403 | const url = new URL(request.body.url); |
| 404 | 404 | url.pathname += '/object_info'; |
| 405 | 405 | |
| 406 | 406 | const result = await fetch(url); |
| 407 | 407 | if (!result.ok) { |
| @@ -430,7 +430,7 @@ comfy.post('/models', jsonParser, async (request, response) => { | ||
| 430 | 430 | comfy.post('/schedulers', jsonParser, async (request, response) => { |
| 431 | 431 | try { |
| 432 | 432 | const url = new URL(request.body.url); |
| 433 | 433 | url.pathname += '/object_info'; |
| 434 | 434 | |
| 435 | 435 | const result = await fetch(url); |
| 436 | 436 | if (!result.ok) { |
| @@ -449,7 +449,7 @@ comfy.post('/schedulers', jsonParser, async (request, response) => { | ||
| 449 | 449 | comfy.post('/vaes', jsonParser, async (request, response) => { |
| 450 | 450 | try { |
| 451 | 451 | const url = new URL(request.body.url); |
| 452 | 452 | url.pathname += '/object_info'; |
| 453 | 453 | |
| 454 | 454 | const result = await fetch(url); |
| 455 | 455 | if (!result.ok) { |
| @@ -517,14 +517,14 @@ comfy.post('/delete-workflow', jsonParser, async (request, response) => { | ||
| 517 | 517 | comfy.post('/generate', jsonParser, async (request, response) => { |
| 518 | 518 | try { |
| 519 | 519 | const url = new URL(request.body.url); |
| 520 | 520 | url.pathname += '/prompt'; |
| 521 | 521 | |
| 522 | 522 | const controller = new AbortController(); |
| 523 | 523 | request.socket.removeAllListeners('close'); |
| 524 | 524 | request.socket.on('close', function () { |
| 525 | 525 | if (!response.writableEnded && !item) { |
| 526 | 526 | const interruptUrl = new URL(request.body.url); |
| 527 | 527 | interruptUrl.pathname += '/interrupt'; |
| 528 | 528 | fetch(interruptUrl, { method: 'POST', headers: { 'Authorization': getBasicAuthHeader(request.body.auth) } }); |
| 529 | 529 | } |
| 530 | 530 | controller.abort(); |
| @@ -544,7 +544,7 @@ comfy.post('/generate', jsonParser, async (request, response) => { | ||
| 544 | 544 | const id = data.prompt_id; |
| 545 | 545 | let item; |
| 546 | 546 | const historyUrl = new URL(request.body.url); |
| 547 | 547 | historyUrl.pathname += '/history'; |
| 548 | 548 | while (true) { |
| 549 | 549 | const result = await fetch(historyUrl); |
| 550 | 550 | if (!result.ok) { |
| @@ -569,7 +569,7 @@ comfy.post('/generate', jsonParser, async (request, response) => { | ||
| 569 | 569 | } |
| 570 | 570 | const imgInfo = Object.keys(item.outputs).map(it => item.outputs[it].images).flat()[0]; |
| 571 | 571 | const imgUrl = new URL(request.body.url); |
| 572 | 572 | imgUrl.pathname += '/view'; |
| 573 | 573 | imgUrl.search = `?filename=${imgInfo.filename}&subfolder=${imgInfo.subfolder}&type=${imgInfo.type}`; |
| 574 | 574 | const imgResponse = await fetch(imgUrl); |
| 575 | 575 | if (!imgResponse.ok) { |