feat(download): 新增感谢下载页面并重构下载流程

- 新增专用的感谢下载页面,支持自动触发下载、SHA512校验值复制与手动重试下载
- 新增下载链接白名单校验机制,避免不安全的任意地址跳转与下载
- 重构官方下载页与测试版申请页面的下载逻辑,统一通过感谢页面完成全流程下载
This commit is contained in:
2026-09-05 20:02:23 +08:00
parent 5997b1c7ea
commit fc6ed1631a
6 changed files with 331 additions and 13 deletions
+50
View File
@@ -19,3 +19,53 @@ export const DATA_MIRRORS = [
"https://gh-proxy.com",
"https://ghfast.top",
] as const;
/** 允许跳转到感谢页并自动下载的地址前缀(官方直链 + 镜像 + 自建 CDN) */
const ALLOWED_DOWNLOAD_PREFIXES = [
"https://github.com/dream-pep/koring-launcher/releases/download/",
"https://gh.ddlc.top/https://github.com/dream-pep/koring-launcher/releases/download/",
"https://gh-proxy.com/https://github.com/dream-pep/koring-launcher/releases/download/",
"https://ghfast.top/https://github.com/dream-pep/koring-launcher/releases/download/",
"https://koring-file-api.lenjing.games/",
"https://koring-launcher-file-api.lenjing.cloud/",
];
/** 校验下载链接是否在白名单内(防止任意地址跳转/自动下载) */
export function isAllowedDownloadUrl(
url: string | null | undefined
): url is string {
return (
typeof url === "string" &&
ALLOWED_DOWNLOAD_PREFIXES.some((p) => url.startsWith(p))
);
}
export type DownloadOsKey = "windows" | "macos" | "linux";
export const DOWNLOAD_OS_META: Record<
DownloadOsKey,
{ label: string; hint: string }
> = {
windows: { label: "Windows", hint: "Windows 安装包(exe" },
macos: { label: "macOS", hint: "macOS 安装包" },
linux: { label: "Linux", hint: "Linux 安装包" },
};
/** 构造感谢下载页跳转地址(附带 下载链接 / 平台 / SHA512 / 加速类型) */
export function buildDownloadThanksUrl(opts: {
url: string;
os: DownloadOsKey;
source: string;
sha512?: string;
name?: string;
version?: string;
}) {
const p = new URLSearchParams();
p.set("url", opts.url);
p.set("os", opts.os);
p.set("source", opts.source);
if (opts.sha512) p.set("sha512", opts.sha512);
if (opts.name) p.set("name", opts.name);
if (opts.version) p.set("version", opts.version);
return `/thanks?${p.toString()}`;
}