Keep video range streams alive during playback
Test, build, and deploy ComfyUI Jobs / test-build (push) Successful in 3m41s
Test, build, and deploy ComfyUI Jobs / deploy (push) Successful in 14s
Test, build, and deploy ComfyUI Jobs / browser-test (push) Failing after 2m29s
Test, build, and deploy ComfyUI Jobs / qa-gate (push) Failing after 5s

This commit is contained in:
2026-11-14 20:32:36 +00:00
parent c2654afa1d
commit adac335bcf
+1 -1
View File
@@ -159,7 +159,7 @@ app.get('/api/comfy/update-status', async (req, res) => { if (!requireUser(req,
app.post('/api/comfy/switch-version', async (req, res) => { const user = requireUser(req, res); if (!user) return; if (user.role !== 'admin') return res.status(403).json({ error: 'Forbidden' }); const requested = String(req.body?.version || '').trim(); if (!requested) return res.status(400).json({ error: 'A ComfyUI version is required' }); try { const versions = await comfyJson('/comfyui_manager/comfyui_versions'); if (!Array.isArray(versions.versions) || !versions.versions.includes(requested)) return res.status(400).json({ error: 'That ComfyUI version is not available' }); await comfyRequest('/comfyui_manager/comfyui_switch_version', 'POST', { ver: requested }); res.json({ ok: true, message: `ComfyUI version switch to ${requested} requested.` }); } catch (error) { res.status(502).json({ error: error.message || 'Unable to switch ComfyUI version' }); } }); app.post('/api/comfy/switch-version', async (req, res) => { const user = requireUser(req, res); if (!user) return; if (user.role !== 'admin') return res.status(403).json({ error: 'Forbidden' }); const requested = String(req.body?.version || '').trim(); if (!requested) return res.status(400).json({ error: 'A ComfyUI version is required' }); try { const versions = await comfyJson('/comfyui_manager/comfyui_versions'); if (!Array.isArray(versions.versions) || !versions.versions.includes(requested)) return res.status(400).json({ error: 'That ComfyUI version is not available' }); await comfyRequest('/comfyui_manager/comfyui_switch_version', 'POST', { ver: requested }); res.json({ ok: true, message: `ComfyUI version switch to ${requested} requested.` }); } catch (error) { res.status(502).json({ error: error.message || 'Unable to switch ComfyUI version' }); } });
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/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/meta', 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' }); const url = assetViewUrl(filename, subfolder, type); try { if (isVideoFilename(filename)) return res.json({ width: null, height: null, sizeBytes: await readVideoSize(url) }); const response = await fetch(url); if (!response.ok) return res.status(response.status).json({ error: 'Asset unavailable' }); const buffer = Buffer.from(await response.arrayBuffer()); let width = null; let height = null; try { const image = await sharp(buffer).metadata(); width = image.width || null; height = image.height || null; } catch { /* Metadata is not available for this asset. */ } res.json({ width, height, sizeBytes: buffer.length }); } catch (error) { res.status(502).json({ error: error.message || 'Unable to read asset metadata' }); } }); app.get('/api/assets/meta', 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' }); const url = assetViewUrl(filename, subfolder, type); try { if (isVideoFilename(filename)) return res.json({ width: null, height: null, sizeBytes: await readVideoSize(url) }); const response = await fetch(url); if (!response.ok) return res.status(response.status).json({ error: 'Asset unavailable' }); const buffer = Buffer.from(await response.arrayBuffer()); let width = null; let height = null; try { const image = await sharp(buffer).metadata(); width = image.width || null; height = image.height || null; } catch { /* Metadata is not available for this asset. */ } res.json({ width, height, sizeBytes: buffer.length }); } catch (error) { res.status(502).json({ error: error.message || 'Unable to read asset metadata' }); } });
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' }); const url = assetViewUrl(filename, subfolder, type); const controller = new AbortController(); const abort = () => { if (!res.writableEnded) controller.abort(); }; req.on('aborted', abort); res.on('close', abort); try { const headers = {}; if (req.headers.range) headers.Range = req.headers.range; const response = await fetch(url, { headers, signal: controller.signal }); if (!response.ok) return res.status(response.status).send('Asset unavailable'); copyAssetHeaders(response, res); res.status(response.status); if (!response.body) return res.end(); Readable.fromWeb(response.body).on('error', (error) => { if (!res.headersSent) res.status(502); res.destroy(error); }).pipe(res); } catch (error) { if (error.name === 'AbortError') return; if (!res.headersSent) res.status(502).json({ error: error.message || 'Unable to read ComfyUI asset' }); else res.destroy(error); } }); 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' }); const url = assetViewUrl(filename, subfolder, type); const controller = new AbortController(); const abort = () => { if (!res.writableEnded) controller.abort(); }; req.on('aborted', abort); try { const headers = {}; if (req.headers.range) headers.Range = req.headers.range; const response = await fetch(url, { headers, signal: controller.signal }); if (!response.ok) return res.status(response.status).send('Asset unavailable'); copyAssetHeaders(response, res); res.status(response.status); if (!response.body) return res.end(); Readable.fromWeb(response.body).on('error', (error) => { if (!res.headersSent) res.status(502); res.destroy(error); }).pipe(res); } catch (error) { if (error.name === 'AbortError') return; if (!res.headersSent) res.status(502).json({ error: error.message || 'Unable to read ComfyUI asset' }); else res.destroy(error); } });
app.use(express.static(browserDir, { index: false })); app.use(express.static(browserDir, { index: false }));
app.use((req, res, next) => { if (req.path.startsWith('/login') || req.path.startsWith('/api/')) return next(); if (!currentUser(req)) return res.redirect('/login'); next(); }); app.use((req, res, next) => { if (req.path.startsWith('/login') || req.path.startsWith('/api/')) return next(); if (!currentUser(req)) return res.redirect('/login'); next(); });
app.use((_req, res) => { if (!fs.existsSync(indexHtml)) return res.status(500).send('Build output missing.'); res.type('html').send(fs.readFileSync(indexHtml, 'utf8')); }); app.use((_req, res) => { if (!fs.existsSync(indexHtml)) return res.status(500).send('Build output missing.'); res.type('html').send(fs.readFileSync(indexHtml, 'utf8')); });