Bound offline ComfyUI metadata probes
| @@ -383,12 +383,23 @@ router.post('/sd-next/upscalers', async (request, response) => { | |||
| 383 | }); | 383 | }); |
| 384 | 384 | ||
| 385 | const comfy = express.Router(); | 385 | const comfy = express.Router(); |
| 386 | const COMFY_METADATA_TIMEOUT_MS = 5000; | ||
| 387 | |||
| 388 | /** | ||
| 389 | * Fetches lightweight ComfyUI status or metadata without allowing an offline | ||
| 390 | * backend to occupy a browser-facing request until the OS TCP timeout. | ||
| 391 | * @param {URL} url ComfyUI endpoint URL | ||
| 392 | * @returns {Promise<import('node-fetch').Response>} Fetch response | ||
| 393 | */ | ||
| 394 | function fetchComfyMetadata(url) { | ||
| 395 | return fetch(url, { signal: AbortSignal.timeout(COMFY_METADATA_TIMEOUT_MS) }); | ||
| 396 | } | ||
| 386 | 397 | ||
| 387 | comfy.post('/ping', async (request, response) => { | 398 | comfy.post('/ping', async (request, response) => { |
| 388 | try { | 399 | try { |
| 389 | const url = new URL(urlJoin(request.body.url, '/system_stats')); | 400 | const url = new URL(urlJoin(request.body.url, '/system_stats')); |
| 390 | 401 | ||
| 391 | const result = await fetch(url); | 402 | const result = await fetchComfyMetadata(url); |
| 392 | if (!result.ok) { | 403 | if (!result.ok) { |
| 393 | throw new Error('ComfyUI returned an error.'); | 404 | throw new Error('ComfyUI returned an error.'); |
| 394 | } | 405 | } |
| @@ -404,7 +415,7 @@ comfy.post('/samplers', async (request, response) => { | |||
| 404 | try { | 415 | try { |
| 405 | const url = new URL(urlJoin(request.body.url, '/object_info')); | 416 | const url = new URL(urlJoin(request.body.url, '/object_info')); |
| 406 | 417 | ||
| 407 | const result = await fetch(url); | 418 | const result = await fetchComfyMetadata(url); |
| 408 | if (!result.ok) { | 419 | if (!result.ok) { |
| 409 | throw new Error('ComfyUI returned an error.'); | 420 | throw new Error('ComfyUI returned an error.'); |
| 410 | } | 421 | } |
| @@ -422,7 +433,7 @@ comfy.post('/models', async (request, response) => { | |||
| 422 | try { | 433 | try { |
| 423 | const url = new URL(urlJoin(request.body.url, '/object_info')); | 434 | const url = new URL(urlJoin(request.body.url, '/object_info')); |
| 424 | 435 | ||
| 425 | const result = await fetch(url); | 436 | const result = await fetchComfyMetadata(url); |
| 426 | if (!result.ok) { | 437 | if (!result.ok) { |
| 427 | throw new Error('ComfyUI returned an error.'); | 438 | throw new Error('ComfyUI returned an error.'); |
| 428 | } | 439 | } |
| @@ -450,7 +461,7 @@ comfy.post('/schedulers', async (request, response) => { | |||
| 450 | try { | 461 | try { |
| 451 | const url = new URL(urlJoin(request.body.url, '/object_info')); | 462 | const url = new URL(urlJoin(request.body.url, '/object_info')); |
| 452 | 463 | ||
| 453 | const result = await fetch(url); | 464 | const result = await fetchComfyMetadata(url); |
| 454 | if (!result.ok) { | 465 | if (!result.ok) { |
| 455 | throw new Error('ComfyUI returned an error.'); | 466 | throw new Error('ComfyUI returned an error.'); |
| 456 | } | 467 | } |
| @@ -468,7 +479,7 @@ comfy.post('/vaes', async (request, response) => { | |||
| 468 | try { | 479 | try { |
| 469 | const url = new URL(urlJoin(request.body.url, '/object_info')); | 480 | const url = new URL(urlJoin(request.body.url, '/object_info')); |
| 470 | 481 | ||
| 471 | const result = await fetch(url); | 482 | const result = await fetchComfyMetadata(url); |
| 472 | if (!result.ok) { | 483 | if (!result.ok) { |
| 473 | throw new Error('ComfyUI returned an error.'); | 484 | throw new Error('ComfyUI returned an error.'); |
| 474 | } | 485 | } |
| @@ -486,7 +497,7 @@ comfy.post('/loras', async (request, response) => { | |||
| 486 | try { | 497 | try { |
| 487 | const url = new URL(urlJoin(request.body.url, '/object_info')); | 498 | const url = new URL(urlJoin(request.body.url, '/object_info')); |
| 488 | 499 | ||
| 489 | const result = await fetch(url); | 500 | const result = await fetchComfyMetadata(url); |
| 490 | if (!result.ok) { | 501 | if (!result.ok) { |
| 491 | throw new Error('ComfyUI returned an error.'); | 502 | throw new Error('ComfyUI returned an error.'); |
| 492 | } | 503 | } |