Skip to content

Commit 5179ad7

Browse files
committed
🚨 新增下载链接模糊检测,不可用切换代理,修复编译警告
1 parent a50031c commit 5179ad7

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

docs/.vitepress/components/current-download.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,30 @@ const installFor = (lang: string, os: string) => {
6464
}
6565
};
6666

67-
export async function currentActions2(lang: string): Promise<HeroAction> {
68-
const userAgent = navigator.userAgent;
67+
/// 模糊检测下载链接是否可用,不可用使用代理切换
68+
const checkDownloadLink = async (link: string): Promise<string> => {
69+
if (link.length > 0) {
70+
try {
71+
const _ = await fetch(link, { method: "HEAD", mode: "no-cors" });
72+
return link;
73+
} catch {
74+
return `https://mirror.ghproxy.com/?q=${link}`;
75+
}
76+
}
77+
78+
return link;
79+
};
6980

81+
export async function currentActions2(lang: string): Promise<HeroAction> {
7082
let action: HeroAction = {
7183
theme: "alt",
7284
text: "",
73-
link: "",
85+
link: "javascript:void(0);",
7486
};
87+
88+
if (typeof navigator === "undefined") return action;
89+
90+
const userAgent = navigator.userAgent;
7591
if (/Win/i.test(navigator.platform)) {
7692
action.text = downloadFor(lang, "Windows");
7793
const arch = await detectPlatformArch();
@@ -136,5 +152,7 @@ export async function currentActions2(lang: string): Promise<HeroAction> {
136152
}
137153
}
138154

155+
action.link = await checkDownloadLink(action.link);
156+
139157
return action;
140158
}

docs/.vitepress/config.mts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,11 @@ export default defineConfig({
6767
// ar: { label: "Arabic", ...ar },
6868
},
6969
vite,
70+
vue: {
71+
template: {
72+
compilerOptions: {
73+
isCustomElement: (tag) => tag === "dweb-wallpaper"
74+
}
75+
}
76+
}
7077
});

0 commit comments

Comments
 (0)