Support ComfyUI hosted on relative URLs Closes #3208

5739efc59b2233374d2fbb7ac7be242f1cad0b22

Cohee <18619528+Cohee1207@users.noreply.github.com>

2 files changed, +11 -10Ignore whitespace
public/scripts/extensions/stable-diffusion/index.js+2 -1
@@ -1111,7 +1111,8 @@ function onHrSecondPassStepsInput() {
11111111}
11121112
11131113function 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(/\/$/, '');
11151116 saveSettingsDebounced();
11161117}
11171118
src/endpoints/stable-diffusion.js+9 -9
@@ -365,7 +365,7 @@ const comfy = express.Router();
365365comfy.post('/ping', jsonParser, async (request, response) => {
366366 try {
367367 const url = new URL(request.body.url);
368368 url.pathname += '/system_stats';
369369
370370 const result = await fetch(url);
371371 if (!result.ok) {
@@ -382,7 +382,7 @@ comfy.post('/ping', jsonParser, async (request, response) => {
382382comfy.post('/samplers', jsonParser, async (request, response) => {
383383 try {
384384 const url = new URL(request.body.url);
385385 url.pathname += '/object_info';
386386
387387 const result = await fetch(url);
388388 if (!result.ok) {
@@ -401,7 +401,7 @@ comfy.post('/samplers', jsonParser, async (request, response) => {
401401comfy.post('/models', jsonParser, async (request, response) => {
402402 try {
403403 const url = new URL(request.body.url);
404404 url.pathname += '/object_info';
405405
406406 const result = await fetch(url);
407407 if (!result.ok) {
@@ -430,7 +430,7 @@ comfy.post('/models', jsonParser, async (request, response) => {
430430comfy.post('/schedulers', jsonParser, async (request, response) => {
431431 try {
432432 const url = new URL(request.body.url);
433433 url.pathname += '/object_info';
434434
435435 const result = await fetch(url);
436436 if (!result.ok) {
@@ -449,7 +449,7 @@ comfy.post('/schedulers', jsonParser, async (request, response) => {
449449comfy.post('/vaes', jsonParser, async (request, response) => {
450450 try {
451451 const url = new URL(request.body.url);
452452 url.pathname += '/object_info';
453453
454454 const result = await fetch(url);
455455 if (!result.ok) {
@@ -517,14 +517,14 @@ comfy.post('/delete-workflow', jsonParser, async (request, response) => {
517517comfy.post('/generate', jsonParser, async (request, response) => {
518518 try {
519519 const url = new URL(request.body.url);
520520 url.pathname += '/prompt';
521521
522522 const controller = new AbortController();
523523 request.socket.removeAllListeners('close');
524524 request.socket.on('close', function () {
525525 if (!response.writableEnded && !item) {
526526 const interruptUrl = new URL(request.body.url);
527527 interruptUrl.pathname += '/interrupt';
528528 fetch(interruptUrl, { method: 'POST', headers: { 'Authorization': getBasicAuthHeader(request.body.auth) } });
529529 }
530530 controller.abort();
@@ -544,7 +544,7 @@ comfy.post('/generate', jsonParser, async (request, response) => {
544544 const id = data.prompt_id;
545545 let item;
546546 const historyUrl = new URL(request.body.url);
547547 historyUrl.pathname += '/history';
548548 while (true) {
549549 const result = await fetch(historyUrl);
550550 if (!result.ok) {
@@ -569,7 +569,7 @@ comfy.post('/generate', jsonParser, async (request, response) => {
569569 }
570570 const imgInfo = Object.keys(item.outputs).map(it => item.outputs[it].images).flat()[0];
571571 const imgUrl = new URL(request.body.url);
572572 imgUrl.pathname += '/view';
573573 imgUrl.search = `?filename=${imgInfo.filename}&subfolder=${imgInfo.subfolder}&type=${imgInfo.type}`;
574574 const imgResponse = await fetch(imgUrl);
575575 if (!imgResponse.ok) {