/**
* GET /deploy — release distribution status page.
*
* Shows the currently-deployed hyper-overlay manifest (file list, total
* size, hashes) plus swarm/peer state for the deploy service. v3 uses
* hyper-overlay directly; there's no release-branch setup form (the
* pear-git v1 "configured" UI was for the release-branch system that v3
* replaces).
*/
import { layout, escapeHtml, formatBytes } from '../helpers.js'
export async function renderDeploy (svc, ctx) {
const prefix = (ctx && ctx.prefix) || ''
const deploy = svc._deploy
const active = !!deploy
let files = []
let totalSize = 0
let topic = null
let connections = 0
if (deploy && deploy.manifest) {
files = deploy.manifest.files || []
totalSize = deploy.manifest.totalSize || 0
topic = deploy.topicHex
connections = deploy.connections
}
const dir = deploy && deploy.dir ? deploy.dir : null
const body = `
<h1>deploy</h1>
<div class="card">
<h2>Deploy service</h2>
<div class="row"><div class="label">status</div><div>${active ? '<span class="badge badge-open">active</span>' : '<span class="badge badge-closed">inactive (no swarm)</span>'}</div></div>
${active ? `
<div class="row"><div class="label">topic</div><div class="meta mono" style="font-size:0.7rem">${escapeHtml(topic)}</div></div>
<div class="row"><div class="label">peers</div><div>${connections}</div></div>
<div class="row"><div class="label">files</div><div>${files.length}</div></div>
<div class="row"><div class="label">total size</div><div>${formatBytes(totalSize)}</div></div>
${dir ? `<div class="row"><div class="label">directory</div><div class="meta mono" style="font-size:0.7rem">${escapeHtml(dir)}</div></div>` : ''}
<form action="${prefix}/deploy/rescan" method="POST" style="margin-top:0.8rem">
<button type="submit">Rescan + republish</button>
<span class="meta" style="margin-left:0.6rem;font-size:0.7rem">Re-indexes the deploy directory and announces a fresh manifest to peers.</span>
</form>
` : `
<div class="meta">Enable swarm in the daemon config to activate the deploy service.</div>
`}
</div>
${active && files.length > 0 ? `
<div class="card">
<h2>Currently deployed — ${files.length} file${files.length === 1 ? '' : 's'}</h2>
${files.map(f => `
<div class="item">
<div class="title">${escapeHtml(f.path)}</div>
<div class="meta">${formatBytes(f.size)}${f.hash ? ' · ' + escapeHtml(f.hash.slice(0, 16)) + '…' : ''}</div>
</div>`).join('')}
</div>
` : active ? '<div class="card"><h2>Currently deployed</h2><div class="empty">(no release files yet — place files in the releases/ directory)</div></div>' : ''}
`
return layout('deploy', '/deploy', body, ctx)
}