Bound offline ComfyUI metadata probes

f4309221b126179b42ec9664e0948610685fba54

permissionBRICK <40219477+permissionBRICK@users.noreply.github.com>

1 files changed, +17 -6Ignore whitespace
src/endpoints/stable-diffusion.js+17 -6
@@ -383,12 +383,23 @@ router.post('/sd-next/upscalers', async (request, response) => {
383383});
384384
385385const 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+}
386397
387398comfy.post('/ping', async (request, response) => {
388399 try {
389400 const url = new URL(urlJoin(request.body.url, '/system_stats'));
390401
391402 const result = await fetchfetchComfyMetadata(url);
392403 if (!result.ok) {
393404 throw new Error('ComfyUI returned an error.');
394405 }
@@ -404,7 +415,7 @@ comfy.post('/samplers', async (request, response) => {
404415 try {
405416 const url = new URL(urlJoin(request.body.url, '/object_info'));
406417
407418 const result = await fetchfetchComfyMetadata(url);
408419 if (!result.ok) {
409420 throw new Error('ComfyUI returned an error.');
410421 }
@@ -422,7 +433,7 @@ comfy.post('/models', async (request, response) => {
422433 try {
423434 const url = new URL(urlJoin(request.body.url, '/object_info'));
424435
425436 const result = await fetchfetchComfyMetadata(url);
426437 if (!result.ok) {
427438 throw new Error('ComfyUI returned an error.');
428439 }
@@ -450,7 +461,7 @@ comfy.post('/schedulers', async (request, response) => {
450461 try {
451462 const url = new URL(urlJoin(request.body.url, '/object_info'));
452463
453464 const result = await fetchfetchComfyMetadata(url);
454465 if (!result.ok) {
455466 throw new Error('ComfyUI returned an error.');
456467 }
@@ -468,7 +479,7 @@ comfy.post('/vaes', async (request, response) => {
468479 try {
469480 const url = new URL(urlJoin(request.body.url, '/object_info'));
470481
471482 const result = await fetchfetchComfyMetadata(url);
472483 if (!result.ok) {
473484 throw new Error('ComfyUI returned an error.');
474485 }
@@ -486,7 +497,7 @@ comfy.post('/loras', async (request, response) => {
486497 try {
487498 const url = new URL(urlJoin(request.body.url, '/object_info'));
488499
489500 const result = await fetchfetchComfyMetadata(url);
490501 if (!result.ok) {
491502 throw new Error('ComfyUI returned an error.');
492503 }