"use client"; import { useEffect, useState } from "react"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { Download, Package, Calendar, HardDrive, ShieldCheck, Copy, Check, Loader2, AlertCircle, ArrowUpRight, GitBranch, FileText, Inbox, } from "lucide-react"; import { cn } from "@/lib/utils"; import { ReleaseNotes } from "@/components/release-notes"; import { DOWNLOAD_SOURCES, resolveDownloadUrl, type DownloadSourceKey, } from "@/lib/download-sources"; interface ChannelPlatform { name: string; url: string; size?: number; sha512?: string; } interface ChannelData { version: string; tag?: string; releaseDate?: string; releaseNotes?: string; htmlUrl?: string; windows?: ChannelPlatform | null; macos?: ChannelPlatform | null; linux?: ChannelPlatform | null; } interface DownloadData { source?: "github" | "legacy"; stable: ChannelData | null; preview: ChannelData | null; } const CHANNEL_META = [ { key: "stable" as const, label: "正式版", desc: "稳定渠道,与自动更新的慢走模式一致" }, { key: "preview" as const, label: "预览版", desc: "抢先体验新功能,可能存在不稳定因素" }, ]; export default function DownloadPage() { const [data, setData] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const [channel, setChannel] = useState<"stable" | "preview">("stable"); const [downloadSource, setDownloadSource] = useState("github"); const [copied, setCopied] = useState(false); useEffect(() => { fetch("/api/download-version") .then((res) => { if (!res.ok) throw new Error(`HTTP ${res.status}`); return res.json(); }) .then((json: DownloadData) => { setData(json); setLoading(false); }) .catch((err) => { setError(err.message); setLoading(false); }); }, []); // 当前渠道:选中的不存在时自动回退到可用渠道 const activeKey = data && data[channel] ? channel : data?.stable ? "stable" : "preview"; const active = data ? data[activeKey] : null; const win = active?.windows || null; const isGithub = data?.source === "github"; const formatSize = (bytes?: number) => bytes ? `${(bytes / 1024 / 1024).toFixed(1)} MB` : "未知"; const formatDate = (d?: string) => d ? new Date(d).toLocaleDateString("zh-CN") : "未知"; const handleDownload = () => { if (!win?.url) return; window.open(resolveDownloadUrl(downloadSource, win.url), "_blank"); }; const copySha = async () => { if (!win?.sha512) return; try { await navigator.clipboard.writeText(win.sha512); setCopied(true); setTimeout(() => setCopied(false), 1500); } catch { // 剪贴板不可用时忽略 } }; if (loading) { return (

正在获取版本信息...

); } if (error || !data) { return (

获取版本信息失败

); } if (!active) { return (

暂无可用版本

暂时没有可用的发布版本,请稍后再来看看

); } const meta = CHANNEL_META.find((c) => c.key === activeKey)!; return (
{/* Header */}
下载中心

Koring Launcher

基于 Electron 的 Minecraft 启动器,版本信息与自动更新机制同源( latest.yml),下载安装包即可开始使用

{isGithub && ( 版本信息由 GitHub Releases 自动识别 )}
{/* 渠道切换 */}
{CHANNEL_META.map((c) => { const d = c.key === "stable" ? data.stable : data.preview; return ( ); })}
{/* 渠道信息卡 */}

{active.version}

{meta.label}

{meta.desc}

{active.htmlUrl && ( 在 GitHub 查看发布页 )}
{/* 元信息 */}

发布时间

{formatDate(active.releaseDate)}

文件大小

{formatSize(win?.size)}

{/* 下载区 */} {win ? (
下载源 {DOWNLOAD_SOURCES.map((s) => ( ))}
{win.name}
{!active.macos && !active.linux && (

macOS / Linux 版本尚未提供,敬请期待

)}
) : (
此渠道暂未提供安装包
)}
{/* 更新内容 */} {active.releaseNotes && (

此版本的变更

)}
); }