"use client"; import { useEffect, useState } from "react"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter, } from "@/components/ui/dialog"; import { Monitor, Apple, Terminal, Loader2, AlertCircle, Package, Hash, Calendar, GitBranch, PackageOpen, ArrowUpRight, FileText, Download, } 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 License { isNeedAgreat: string; title: string; text: string; liceURL: string; } interface PlatformInfo { isNoVersion: string; licence: License; DownlodeURL: string; } interface AboutVersion { about: string; "about-list": Record; } interface BetaData { version: string; builddate: string; /** 数据来源:github = GitHub Releases 自动识别;legacy = 旧静态源兜底 */ source?: "github" | "legacy"; tag?: string; htmlUrl?: string; releaseNotes?: string; /** GitHub 可达但没有预览版时的标记 */ noRelease?: boolean; app: { windows: PlatformInfo; macos: PlatformInfo; linux: PlatformInfo; }; aboutversion?: AboutVersion; } const platforms = [ { key: "windows" as const, label: "Windows", icon: Monitor }, { key: "macos" as const, label: "macOS", icon: Apple }, { key: "linux" as const, label: "Linux", icon: Terminal }, ]; export default function JoinBetaPage() { const [data, setData] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const [dialogOpen, setDialogOpen] = useState(false); const [activePlatform, setActivePlatform] = useState(null); const [downloadSource, setDownloadSource] = useState("github"); useEffect(() => { fetch("/api/beta-version") .then((res) => { if (!res.ok) throw new Error(`HTTP ${res.status}`); return res.json(); }) .then((json: BetaData) => { setData(json); setLoading(false); }) .catch((err) => { setError(err.message); setLoading(false); }); }, []); const handleDownload = (platform: PlatformInfo) => { if (platform.licence.isNeedAgreat === "true") { setActivePlatform(platform); setDialogOpen(true); } else { window.open( resolveDownloadUrl(downloadSource, platform.DownlodeURL), "_blank" ); } }; const confirmDownload = () => { if (activePlatform?.DownlodeURL) { window.open( resolveDownloadUrl(downloadSource, activePlatform.DownlodeURL), "_blank" ); } setDialogOpen(false); setActivePlatform(null); }; if (loading) { return (

正在获取版本信息...

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

获取版本信息失败

); } if (data.noRelease) { return (

暂无预览版本

GitHub Releases 中暂时没有可用的预览(Beta)版本,请稍后再来看看

); } return (
{/* Header */}
加入 Beta 测试

Koring Launcher

参与 Koring Launcher 的 Beta 测试计划,抢先体验最新功能

{data.source === "github" ? ( <> 版本信息由 GitHub Releases 自动识别 {data.htmlUrl && ( 在 GitHub 查看发布页 )} ) : ( 版本信息来自缓存数据源 )}
{/* Version Info Card */}

版本号

{data.version}

{data.source === "github" ? ( ) : ( )}

{data.source === "github" ? "发布时间" : "编译号"}

{data.source === "github" ? data.builddate ? new Date(data.builddate).toLocaleDateString("zh-CN") : "未知" : data.builddate}

{/* Platform Cards */}

选择平台

{data.source === "github" && platforms.some(({ key }) => !!data.app[key].DownlodeURL) && (
下载源 {DOWNLOAD_SOURCES.map((s) => ( ))}
)}
{platforms.map(({ key, label, icon: Icon }) => { const platform = data.app[key]; const noVersion = platform.isNoVersion === "true"; return (
{label}
{noVersion ? (

未提供对应版本

) : ( )}
); })}
{/* Release Notes / About This Version */}

{data.releaseNotes ? "版本更新内容" : "关于此版本"}

{data.releaseNotes ? ( ) : data.aboutversion ? ( <>

{data.aboutversion.about}

    {Object.entries(data.aboutversion["about-list"]).map( ([key, text]) => (
  • {text}
  • ) )}
) : null}
{/* License Dialog */} {activePlatform?.licence.title} {activePlatform?.licence.text} {activePlatform?.licence.liceURL && ( 查看《Koring APP Beta 测试协议》 )}
); }