Bound offline ComfyUI metadata probes
| @@ -383,12 +383,23 @@ router.post('/sd-next/upscalers', async (request, response) => { | ||
| 383 | 383 | }); |
| 384 | 384 | |
| 385 | 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 | 398 | comfy.post('/ping', async (request, response) => { |
| 388 | 399 | try { |
| 389 | 400 | const url = new URL(urlJoin(request.body.url, '/system_stats')); |
| 390 | 401 | |
| 391 | 402 | const result = await fetchfetchComfyMetadata(url); |
| 392 | 403 | if (!result.ok) { |
| 393 | 404 | throw new Error('ComfyUI returned an error.'); |
| 394 | 405 | } |
| @@ -404,7 +415,7 @@ comfy.post('/samplers', async (request, response) => { | ||
| 404 | 415 | try { |
| 405 | 416 | const url = new URL(urlJoin(request.body.url, '/object_info')); |
| 406 | 417 | |
| 407 | 418 | const result = await fetchfetchComfyMetadata(url); |
| 408 | 419 | if (!result.ok) { |
| 409 | 420 | throw new Error('ComfyUI returned an error.'); |
| 410 | 421 | } |
| @@ -422,7 +433,7 @@ comfy.post('/models', async (request, response) => { | ||
| 422 | 433 | try { |
| 423 | 434 | const url = new URL(urlJoin(request.body.url, '/object_info')); |
| 424 | 435 | |
| 425 | 436 | const result = await fetchfetchComfyMetadata(url); |
| 426 | 437 | if (!result.ok) { |
| 427 | 438 | throw new Error('ComfyUI returned an error.'); |
| 428 | 439 | } |
| @@ -450,7 +461,7 @@ comfy.post('/schedulers', async (request, response) => { | ||
| 450 | 461 | try { |
| 451 | 462 | const url = new URL(urlJoin(request.body.url, '/object_info')); |
| 452 | 463 | |
| 453 | 464 | const result = await fetchfetchComfyMetadata(url); |
| 454 | 465 | if (!result.ok) { |
| 455 | 466 | throw new Error('ComfyUI returned an error.'); |
| 456 | 467 | } |
| @@ -468,7 +479,7 @@ comfy.post('/vaes', async (request, response) => { | ||
| 468 | 479 | try { |
| 469 | 480 | const url = new URL(urlJoin(request.body.url, '/object_info')); |
| 470 | 481 | |
| 471 | 482 | const result = await fetchfetchComfyMetadata(url); |
| 472 | 483 | if (!result.ok) { |
| 473 | 484 | throw new Error('ComfyUI returned an error.'); |
| 474 | 485 | } |
| @@ -486,7 +497,7 @@ comfy.post('/loras', async (request, response) => { | ||
| 486 | 497 | try { |
| 487 | 498 | const url = new URL(urlJoin(request.body.url, '/object_info')); |
| 488 | 499 | |
| 489 | 500 | const result = await fetchfetchComfyMetadata(url); |
| 490 | 501 | if (!result.ok) { |
| 491 | 502 | throw new Error('ComfyUI returned an error.'); |
| 492 | 503 | } |