"use client"; import { useEffect, useMemo, useState } from "react"; import Link from "next/link"; import { useSearchParams } from "next/navigation"; import { Button } from "@/components/ui/button"; import { PartyPopper, Download, ShieldCheck, Copy, Check, RotateCw, Monitor, Apple, Terminal, AlertCircle, ArrowRight, type LucideIcon, } from "lucide-react"; import { cn } from "@/lib/utils"; import { DOWNLOAD_SOURCES, DOWNLOAD_OS_META, isAllowedDownloadUrl, type DownloadOsKey, } from "@/lib/download-sources"; const OS_ICON: Record = { windows: Monitor, macos: Apple, linux: Terminal, }; export function ThanksView() { const searchParams = useSearchParams(); const [autoStarted, setAutoStarted] = useState(false); const [copied, setCopied] = useState(false); const url = searchParams.get("url"); const osParam = searchParams.get("os") || ""; const sha512 = searchParams.get("sha512") || ""; const sourceKey = searchParams.get("source") || ""; const name = searchParams.get("name") || ""; const version = searchParams.get("version") || ""; const os = ( osParam === "windows" || osParam === "macos" || osParam === "linux" ? osParam : "windows" ) as DownloadOsKey; const osMeta = DOWNLOAD_OS_META[os]; const OsIcon = OS_ICON[os]; const allowed = isAllowedDownloadUrl(url); const sourceLabel = useMemo(() => { const s = DOWNLOAD_SOURCES.find((d) => d.key === sourceKey); if (s) return s.label; return sourceKey === "legacy" ? "官方缓存源" : sourceKey || "默认源"; }, [sourceKey]); /** 触发浏览器下载(隐藏 a 标签,同页不离开) */ const triggerDownload = () => { if (!allowed || !url) return; const a = document.createElement("a"); a.href = url; a.rel = "noopener noreferrer"; a.style.display = "none"; document.body.appendChild(a); a.click(); a.remove(); }; // 自动开始下载 useEffect(() => { if (!allowed || !url || autoStarted) return; setAutoStarted(true); const timer = setTimeout(triggerDownload, 800); return () => clearTimeout(timer); // eslint-disable-next-line react-hooks/exhaustive-deps }, [url, allowed]); const copySha = async () => { if (!sha512) return; try { await navigator.clipboard.writeText(sha512); setCopied(true); setTimeout(() => setCopied(false), 1500); } catch { // 忽略剪贴板不可用 } }; return (
{/* 主卡片 */}
{allowed ? ( <>

感谢下载 Koring Launcher

{autoStarted ? "下载已自动开始,如果未弹出请点击下方按钮" : "下载即将自动开始…"}

{/* 下载内容摘要 */}

下载类型 · {osMeta.hint}

{name || `${osMeta.label} 安装包`} {version ? `(v${version})` : ""}

加速类型

{sourceLabel}

{/* 操作 */}
) : ( <>

下载链接无效

下载地址不在允许范围内,未自动开始下载。

)}
{/* 底部提示 */} {allowed && (

如浏览器拦截下载,请点击上方"重新下载";安装时建议校验文件 SHA512 完整性。

)}
); }