const platformOrder = ['windows-x64', 'macos-arm64', 'macos-x64', 'linux-x64', 'linux-arm64', 'windows-arm64']; const platformNames = { 'windows-x64': 'Windows x64', 'windows-arm64': 'Windows arm64', 'macos-arm64': 'macOS Apple Silicon', 'macos-x64': 'macOS Intel', 'linux-x64': 'Linux x64', 'linux-arm64': 'Linux arm64', }; const platformBadges = { windows: 'WIN', macos: 'MAC', linux: 'LNX', }; function el(tag, className, text) { const node = document.createElement(tag); if (className) node.className = className; if (text !== undefined) node.textContent = text; return node; } function setText(id, value) { const node = document.getElementById(id); if (node) node.textContent = value; } function downloadCard(key, item) { const card = el('article', 'download-card'); const platform = key.split('-')[0]; const icon = el('div', 'platform-icon', platformBadges[platform] || platform.slice(0, 3).toUpperCase()); const title = el('h3', '', platformNames[key] || key); const sub = el('div', 'sub', `${item.format || 'installer'} · ${formatBytes(item.size)}`); const checksum = el('div', 'checksum', `sha256 ${item.sha256 || '—'}`); const link = el('a', 'button button-primary', '下载'); link.href = item.url; link.rel = 'noreferrer'; card.append(icon, title, sub, checksum, link); return card; } function formatBytes(size) { if (!Number.isFinite(Number(size)) || Number(size) <= 0) return '—'; const units = ['B', 'KB', 'MB', 'GB']; let value = Number(size); let index = 0; while (value >= 1024 && index < units.length - 1) { value /= 1024; index += 1; } return `${value.toFixed(index === 0 ? 0 : 1)} ${units[index]}`; } async function loadManifest() { const grid = document.getElementById('download-grid'); const empty = document.getElementById('download-empty'); if (!grid || !empty) return; try { const response = await fetch(`/releases.json?t=${Date.now()}`, { cache: 'no-store' }); if (!response.ok) throw new Error(`HTTP ${response.status}`); const manifest = await response.json(); setText('release-version', `v${manifest.version || '—'}`); setText('release-channel', manifest.channel || 'stable'); setText('release-date', manifest.published_at ? new Date(manifest.published_at).toLocaleDateString(undefined, { month: 'short', day: 'numeric', year: 'numeric' }) : ''); const downloads = manifest.downloads && typeof manifest.downloads === 'object' ? manifest.downloads : {}; const entries = Object.entries(downloads) .filter(([, item]) => item && item.url) .sort(([a], [b]) => { const ai = platformOrder.indexOf(a); const bi = platformOrder.indexOf(b); return (ai === -1 ? 99 : ai) - (bi === -1 ? 99 : bi); }); grid.replaceChildren(...entries.map(([key, item]) => downloadCard(key, item))); grid.hidden = entries.length === 0; empty.classList.toggle('hidden', entries.length > 0); if (manifest.release_notes_url) { const notes = document.getElementById('release-notes'); if (notes) { notes.href = manifest.release_notes_url; notes.classList.remove('hidden'); } } } catch (error) { setText('release-version', '版本信息不可用'); setText('release-date', ''); empty.classList.remove('hidden'); const title = empty.querySelector('strong'); const body = empty.querySelector('p'); if (title) title.textContent = '暂时无法加载版本信息'; if (body) body.textContent = `请稍后刷新页面(${error.message})。`; } } loadManifest();