show asset resolution and file size
Test, build, and deploy ComfyUI Jobs / test-build (push) Successful in 4m0s
Test, build, and deploy ComfyUI Jobs / deploy (push) Successful in 15s

This commit is contained in:
2026-10-03 04:25:06 +00:00
parent dd61b3d416
commit 2d5250ca2d
4 changed files with 9 additions and 21 deletions
+2
View File
@@ -2,6 +2,7 @@ const express = require('express');
const path = require('path');
const fs = require('fs');
const crypto = require('crypto');
const sharp = require('sharp');
const app = express();
const port = Number(process.env.PORT || 7002);
const dataDir = path.join(__dirname, 'data');
@@ -77,6 +78,7 @@ 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(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 { 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/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' }); try { const response = await fetch(comfyUrl(`/view?filename=${encodeURIComponent(filename)}&subfolder=${encodeURIComponent(subfolder)}&type=${encodeURIComponent(type)}`)); 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 { /* Video metadata is not available from sharp. */ } 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' }); 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(); });
app.use(express.static(browserDir, { index: false }));