mirror of
https://github.com/lingke-net/koring-space.git
synced 2026-09-12 05:45:17 +08:00
feat(download): 新增感谢下载页面并重构下载流程
- 新增专用的感谢下载页面,支持自动触发下载、SHA512校验值复制与手动重试下载 - 新增下载链接白名单校验机制,避免不安全的任意地址跳转与下载 - 重构官方下载页与测试版申请页面的下载逻辑,统一通过感谢页面完成全流程下载
This commit is contained in:
+27
-4
@@ -1,6 +1,7 @@
|
||||
"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 {
|
||||
@@ -25,7 +26,9 @@ import { PlatformDownloadGrid } from "@/components/platform-download-grid";
|
||||
import {
|
||||
DOWNLOAD_SOURCES,
|
||||
resolveDownloadUrl,
|
||||
buildDownloadThanksUrl,
|
||||
type DownloadSourceKey,
|
||||
type DownloadOsKey,
|
||||
} from "@/lib/download-sources";
|
||||
|
||||
interface ChannelPlatform {
|
||||
@@ -64,6 +67,7 @@ type Selection =
|
||||
| { kind: "version"; version: string };
|
||||
|
||||
export default function DownloadPage() {
|
||||
const router = useRouter();
|
||||
const [data, setData] = useState<DownloadData | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
@@ -136,9 +140,26 @@ export default function DownloadPage() {
|
||||
}
|
||||
};
|
||||
|
||||
const handlePlatformDownload = (url?: string | null) => {
|
||||
if (!url) return;
|
||||
window.open(resolveDownloadUrl(downloadSource, url), "_blank");
|
||||
/** 点击下载 -> 跳转感谢下载页(携带 链接/平台/SHA512/加速类型),由该页自动下载 */
|
||||
const startThanksDownload = (os: DownloadOsKey) => {
|
||||
const info = (
|
||||
{
|
||||
windows: active?.windows,
|
||||
macos: active?.macos,
|
||||
linux: active?.linux,
|
||||
} as const
|
||||
)[os];
|
||||
if (!info?.url) return;
|
||||
router.push(
|
||||
buildDownloadThanksUrl({
|
||||
url: resolveDownloadUrl(downloadSource, info.url),
|
||||
os,
|
||||
source: downloadSource,
|
||||
sha512: info.sha512,
|
||||
name: info.name,
|
||||
version: active?.version,
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
@@ -394,7 +415,9 @@ export default function DownloadPage() {
|
||||
: null,
|
||||
},
|
||||
]}
|
||||
onDownload={(p) => handlePlatformDownload(p.download?.url)}
|
||||
onDownload={(p) =>
|
||||
startThanksDownload(p.key as DownloadOsKey)
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user