"use client"; import { useEffect, useMemo, useState } from "react"; import { useRouter } from "next/navigation"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter, } from "@/components/ui/dialog"; import { Loader2, AlertCircle, Package, Hash, Calendar, GitBranch, PackageOpen, ArrowUpRight, FileText, History, Monitor, Apple, Terminal, } from "lucide-react"; import { cn } from "@/lib/utils"; import { ReleaseNotes } from "@/components/release-notes"; import { PlatformDownloadGrid } from "@/components/platform-download-grid"; import { DOWNLOAD_SOURCES, resolveDownloadUrl, buildDownloadThanksUrl, type DownloadSourceKey, type DownloadOsKey, } from "@/lib/download-sources"; interface License { isNeedAgreat: string; title: string; text: string; liceURL: string; } interface PlatformInfo { isNoVersion: string; licence: License; DownlodeURL: string; } interface AppInfo { windows: PlatformInfo; macos: PlatformInfo; linux: PlatformInfo; } interface AboutVersion { about: string; "about-list": Record; } /** 历史预览版条目(与顶层字段同构,可覆盖到页面上) */ interface BetaVersionItem { version: string; builddate: string; tag?: string; htmlUrl?: string; releaseNotes?: string; app: AppInfo; } interface BetaData { version: string; builddate: string; /** 数据来源:github = GitHub Releases 自动识别;legacy = 旧静态源兜底 */ source?: "github" | "legacy"; tag?: string; htmlUrl?: string; releaseNotes?: string; /** GitHub 可达但没有预览版时的标记 */ noRelease?: boolean; app: AppInfo; aboutversion?: AboutVersion; /** 历史预览版列表(新 -> 旧) */ versions?: BetaVersionItem[]; } const PLATFORM_SLOTS = ["windows", "macos", "linux"] as const; export default function JoinBetaPage() { const router = useRouter(); 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 [pendingOs, setPendingOs] = useState("windows"); const [downloadSource, setDownloadSource] = useState("github"); /** null = 最新预览版(顶层数据),否则为 data.versions 中的历史版本号 */ const [selectedVersion, setSelectedVersion] = useState(null); 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); }); }, []); // 当前展示的版本:选中的历史版本会覆盖顶层字段(保留 source/versions 等) const active = useMemo(() => { if (!data) return null; if (selectedVersion) { const item = data.versions?.find((v) => v.version === selectedVersion); if (item) return { ...data, ...item }; } return data; }, [data, selectedVersion]); const isGithub = active?.source === "github"; const hasAnyDownload = !!( active && PLATFORM_SLOTS.some((k) => active.app[k].DownlodeURL) ); const formatDate = (d?: string) => d ? new Date(d).toLocaleDateString("zh-CN") : "未知"; /** 跳转感谢下载页(携带 链接/平台/SHA512/加速类型),由该页自动下载 */ const goThanks = (url: string, os: DownloadOsKey) => { router.push( buildDownloadThanksUrl({ url, os, source: downloadSource, version: active?.version, }) ); }; const handleDownload = (platform: PlatformInfo, os: DownloadOsKey) => { if (!platform.DownlodeURL) return; const url = resolveDownloadUrl(downloadSource, platform.DownlodeURL); if (platform.licence.isNeedAgreat === "true") { setActivePlatform(platform); setPendingOs(os); setDialogOpen(true); } else { goThanks(url, os); } }; const confirmDownload = () => { if (activePlatform?.DownlodeURL) { goThanks( resolveDownloadUrl(downloadSource, activePlatform.DownlodeURL), pendingOs ); } setDialogOpen(false); setActivePlatform(null); }; if (loading) { return (

正在获取版本信息...

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

获取版本信息失败

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

暂无预览版本

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

); } if (!active) return null; return (
{/* Header */}
加入 Beta 测试

Koring Launcher

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

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

版本号

{active.version}

{isGithub ? ( ) : ( )}

{isGithub ? "发布时间" : "编译号"}

{isGithub ? formatDate(active.builddate) : active.builddate}

{/* 历史版本选择 */} {data.versions && data.versions.length > 0 && ( )} {/* Platform Cards */}

选择平台

{isGithub && hasAnyDownload && (
下载源 {DOWNLOAD_SOURCES.map((s) => ( ))}
)}
{ const info = active.app[slot.key as keyof AppInfo]; if (info?.DownlodeURL) handleDownload(info, slot.key as DownloadOsKey); }} />
{/* Release Notes / About This Version */}

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

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

{active.aboutversion.about}

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