${esc(p.name)}${p.services} 个服务
${esc(p.file.replace((pend.root || '') + '/', ''))}
${p.images.missing.length
@@ -657,15 +657,23 @@ async function renderContainers(silent, mode = 'running') {
$$('#view [data-pend-cmd]').forEach(b => b.onclick = () => {
alert(`在宿主机执行:\n\ndocker compose -f ${b.dataset.pendCmd} up -d`);
});
- $$('#view [data-pend]').forEach(b => b.onclick = async () => {
- const name = b.dataset.pend;
- if (!confirm(`启动应用「${name}」?\n\n将执行 docker compose up -d,会创建并运行该项目下的容器。`)) return;
- b.disabled = true; b.textContent = '启动中…';
+ const startPend = async (name, el) => {
+ if (el) { el.disabled = true; el.dataset.txt = el.textContent; el.textContent = '启动中…'; }
try {
const r = await api('/api/pending-apps/start', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name }) });
- if (r.ok) { toast(`「${name}」已启动`); setTimeout(() => render(), 1500); }
- else { alert(`启动失败:\n\n${r.output || '未知错误'}`); b.disabled = false; b.textContent = '启动'; }
- } catch (e) { toast(e.message, true); b.disabled = false; b.textContent = '启动'; }
+ toast(r.message || `已启动 ${name}`);
+ setTimeout(render, 1200);
+ } catch (e) {
+ toast(e.message, true);
+ if (el) { el.disabled = false; el.textContent = el.dataset.txt || '启动'; }
+ }
+ };
+ $$('#view [data-pend]').forEach(b => b.onclick = (e) => { e.stopPropagation(); startPend(b.dataset.pend, b); });
+ $$('#view [data-pend-card]').forEach(card => {
+ card.onclick = (e) => {
+ if (e.target.closest('[data-pend]') || e.target.closest('[data-pend-cmd]')) return;
+ startPend(card.dataset.pendCard, card.querySelector('[data-pend]'));
+ };
});
if (mode === 'stopped') {
@@ -869,10 +877,21 @@ async function renderImages() {
${fmtBytes(i.size)} |
${useCell(i)} |
${new Date(i.created * 1000).toLocaleDateString('zh-CN')} |
- ${i.canDelete ? `` : '使用中,不可删除'} |
+
+
+ ${i.canDelete ? `` : '使用中,不可删除'}
+ |
`).join('')}
`;
+ $$('#view [data-export]').forEach(b => b.onclick = () => {
+ const id = b.dataset.export;
+ const a = document.createElement('a');
+ a.href = `/api/images/${encodeURIComponent(id)}/export`;
+ a.download = '';
+ document.body.appendChild(a); a.click(); a.remove();
+ toast('开始导出,浏览器下载中…(大镜像可能需要 1-2 分钟)');
+ });
$$('#view [data-img]').forEach(b => b.onclick = async () => {
if (!confirm('确定删除该镜像?')) return;
try { await api(`/api/images/${encodeURIComponent(b.dataset.img)}?force=1`, { method: 'DELETE' }); toast('已删除'); render(); }
diff --git a/public/style.css b/public/style.css
index cdca5b8..53d9fc3 100644
--- a/public/style.css
+++ b/public/style.css
@@ -333,3 +333,13 @@ table.tb th.num{text-align:right}
.batch-bar .btn[disabled]{opacity:.5;cursor:not-allowed}
.chk{display:flex;align-items:center;margin-right:2px;flex-shrink:0}
.chk input{width:15px;height:15px;cursor:pointer;accent-color:#e5484d}
+
+/* 镜像导出 / 未启动应用整卡点击 */
+.btn.sm{font-size:11.5px;padding:3px 9px;height:26px}
+.btn.ghost{background:#fff;border:1px solid #dfe6ef;color:#5a6b82}
+.btn.ghost:hover{background:#f5f8fc;border-color:#c9d5e4;color:#2d3b4f}
+.img-acts{white-space:nowrap;text-align:right}
+.img-acts .btn + .btn{margin-left:6px}
+.pend-card.act{cursor:pointer;transition:box-shadow .15s,border-color .15s,transform .15s}
+.pend-card.act:hover{border-color:#c9d8ee;box-shadow:0 4px 14px rgba(26,115,232,.12);transform:translateY(-1px)}
+.pend-card.act:active{transform:translateY(0)}
diff --git a/server/index.js b/server/index.js
index dc5e08e..29f7151 100644
--- a/server/index.js
+++ b/server/index.js
@@ -7,6 +7,7 @@ const fsp = require('fs/promises');
const path = require('path');
const os = require('os');
const { PassThrough } = require('stream');
+const zlib = require('zlib');
const { execFile } = require('child_process');
const docker = new Docker({ socketPath: process.env.DOCKER_SOCK || '/var/run/docker.sock' });
@@ -1058,6 +1059,27 @@ app.get('/api/images', async (req, res) => {
} catch (e) { res.status(500).json({ error: e.message }); }
});
+app.get('/api/images/:id/export', async (req, res) => {
+ try {
+ const img = await docker.getImage(req.params.id).inspect();
+ const tag = (img.RepoTags && img.RepoTags[0]) || '';
+ const base = tag ? tag.replace(/[^a-zA-Z0-9._-]+/g, '_').replace(/^_+|_+$/g, '') : img.Id.replace('sha256:', '').slice(0, 12);
+ const name = `${base || 'image'}.tar.gz`;
+ res.setHeader('Content-Type', 'application/gzip');
+ res.setHeader('Content-Disposition', `attachment; filename="${name}"`);
+ res.setHeader('X-Image-Name', name);
+ const stream = await docker.getImage(img.Id).get();
+ const gz = zlib.createGzip({ level: 3 });
+ stream.on('error', (e) => { try { res.end(); } catch (_) {} });
+ gz.on('error', () => { try { res.end(); } catch (_) {} });
+ res.on('close', () => { try { stream.destroy(); gz.destroy(); } catch (_) {} });
+ stream.pipe(gz).pipe(res);
+ } catch (e) {
+ if (!res.headersSent) res.status(500).json({ error: e.message });
+ else try { res.end(); } catch (_) {}
+ }
+});
+
app.delete('/api/images/:id', async (req, res) => {
try {
const id = req.params.id;