show live ComfyUI queue count
Test, build, and deploy ComfyUI Jobs / test-build (push) Successful in 3m58s
Test, build, and deploy ComfyUI Jobs / deploy (push) Successful in 14s

This commit is contained in:
2026-10-03 03:10:13 +00:00
parent 8f6b706a49
commit db94b7f01c
4 changed files with 5 additions and 5 deletions
+2 -2
View File
@@ -38,7 +38,7 @@ function modelsFromPrompt(entry) {
return models.filter((model, index, all) => all.findIndex((item) => item.name === model.name) === index);
}
function assetType(asset) { return /\.(mp4|webm|mov|m4v)$/i.test(asset.filename) ? 'video' : 'image'; }
function serverStatusFromStats(stats) { const system = stats?.system || {}; return { reachable: true, version: system.comfyui_version || '', os: system.os || '', pythonVersion: system.python_version || '', devices: (stats?.devices || []).map((device) => ({ name: device.name || device.type || 'Unknown device', type: device.type || '', vramTotal: device.vram_total || 0, vramFree: device.vram_free || 0 })) }; }
function serverStatusFromStats(stats, queue) { const system = stats?.system || {}; const running = Array.isArray(queue?.queue_running) ? queue.queue_running.length : 0; const pending = Array.isArray(queue?.queue_pending) ? queue.queue_pending.length : 0; return { reachable: true, version: system.comfyui_version || '', os: system.os || '', pythonVersion: system.python_version || '', devices: (stats?.devices || []).map((device) => ({ name: device.name || device.type || 'Unknown device', type: device.type || '', vramTotal: device.vram_total || 0, vramFree: device.vram_free || 0 })), queue: { running, pending, total: running + pending } }; }
function jobFromHistory(promptId, entry) {
const outputs = Object.values(entry?.outputs || {});
const assets = outputs.flatMap((output) => [...(output?.images || []), ...(output?.gifs || []), ...(output?.videos || [])]).filter((asset) => asset?.filename).map((asset) => ({ ...asset, type: assetType(asset), url: `/api/assets?filename=${encodeURIComponent(asset.filename)}&subfolder=${encodeURIComponent(asset.subfolder || '')}&type=${encodeURIComponent(asset.type || 'output')}` }));
@@ -51,7 +51,7 @@ app.post('/api/login', (req, res) => { const user = users().find((item) => item.
app.post('/api/logout', (_req, res) => { res.setHeader('Set-Cookie', 'cp_auth=; Path=/; HttpOnly; SameSite=Lax; Max-Age=0'); res.json({ ok: true }); });
app.get('/api/me', (req, res) => res.json({ user: currentUser(req) }));
app.get('/api/jobs', async (req, res) => { if (!requireUser(req, res)) return; try { res.json({ jobs: await listJobs() }); } catch (error) { res.status(502).json({ error: error.message || 'Unable to read ComfyUI jobs' }); } });
app.get('/api/server-status', async (req, res) => { if (!requireUser(req, res)) return; try { res.json({ status: serverStatusFromStats(await comfyJson('/system_stats')) }); } catch (error) { res.status(502).json({ error: error.message || 'Unable to read ComfyUI server status' }); } });
app.get('/api/server-status', async (req, res) => { if (!requireUser(req, res)) return; try { const [stats, queue] = await Promise.all([comfyJson('/system_stats'), comfyJson('/queue')]); res.json({ status: serverStatusFromStats(stats, queue) }); } catch (error) { res.status(502).json({ error: error.message || 'Unable to read ComfyUI server status' }); } });
app.get('/api/jobs/:promptId', async (req, res) => { if (!requireUser(req, res)) return; try { const history = await comfyJson(`/history/${encodeURIComponent(req.params.promptId)}`); const entry = history?.[req.params.promptId] || history; if (!entry) return res.status(404).json({ error: 'Job not found' }); res.json({ job: jobFromHistory(req.params.promptId, entry) }); } catch (error) { res.status(502).json({ error: error.message || 'Unable to read ComfyUI job' }); } });
app.get('/api/assets', async (req, res) => { if (!requireUser(req, res)) return; const filename = String(req.query.filename || ''); const subfolder = String(req.query.subfolder || ''); const type = String(req.query.type || 'output'); if (!filename || !['output', 'input', 'temp'].includes(type) || filename.includes('..') || subfolder.includes('..')) return res.status(400).json({ error: 'Invalid asset reference' }); try { const response = await fetch(comfyUrl(`/view?filename=${encodeURIComponent(filename)}&subfolder=${encodeURIComponent(subfolder)}&type=${encodeURIComponent(type)}`)); if (!response.ok) return res.status(response.status).send('Asset unavailable'); res.setHeader('Content-Type', response.headers.get('content-type') || 'application/octet-stream'); res.setHeader('Content-Disposition', 'inline'); res.setHeader('Cache-Control', 'private, max-age=300'); res.send(Buffer.from(await response.arrayBuffer())); } catch (error) { res.status(502).json({ error: error.message || 'Unable to read ComfyUI asset' }); } });
app.use((req, res, next) => { if (req.path.startsWith('/login') || req.path.startsWith('/api/')) return next(); if (!currentUser(req)) return res.redirect('/login'); next(); });