Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions docs/.vitepress/components/DownloadPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
<div class="card-header">
<span class="magic-icon">✨</span>
<div class="header-text">
您的设备应该是 <strong>{{ platformName }}</strong>
您的设备应该是
<span class="spacer"></span>
<strong>{{ platformName }}</strong>
<span class="spacer"></span>
<span v-if="archName" class="tag tag-theme">
{{ archName }}
Expand Down Expand Up @@ -242,7 +244,7 @@ const getExtensionName = (name: string) => {
const getArchDisplay = (name: string, platformId: string) => {
const n = name.toLowerCase();
if (n.includes("arm64") || n.includes("aarch64")) return "ARM64";
if (n.includes("x64") || n.includes("amd64")) return "x64";
if (n.includes("x64") || n.includes("x86_64") || n.includes("amd64")) return "x64";
if (n.includes("ia32") || n.includes("x86")) return "32位 (x86)";

if (platformId === "windows") return "x86 / x64 兼容";
Expand All @@ -260,8 +262,8 @@ const sortAssets = (assets: GitHubAsset[]) => {
return assets.sort((a, b) => {
const nA = a.name.toLowerCase();
const nB = b.name.toLowerCase();
const isX64A = nA.includes("x64") || nA.includes("amd64");
const isX64B = nB.includes("x64") || nB.includes("amd64");
const isX64A = nA.includes("x64") || nA.includes("x86_64") || nA.includes("amd64");
const isX64B = nB.includes("x64") || nB.includes("x86_64") || nB.includes("amd64");
if (isX64A && !isX64B) return -1;
if (!isX64A && isX64B) return 1;
return 0;
Expand All @@ -271,7 +273,7 @@ const sortAssets = (assets: GitHubAsset[]) => {
const isArchCompatible = (name: string, targetArch: string) => {
const n = name.toLowerCase();
const isArmAsset = n.includes("arm64") || n.includes("aarch64");
const is32BitAsset = n.includes("ia32") || n.includes("x86");
const is32BitAsset = n.includes("ia32") || (n.includes("x86") && !n.includes("x86_64"));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

这个架构检查逻辑修复了 x86_64 被错误识别为32位的问题,做得很好。不过,我注意到类似的架构检测逻辑(如 ARM64、x64)散布在 getArchDisplaysortAssetsisArchCompatible 等多个函数中。

为了提高代码的可维护性并避免重复,可以考虑将这些检测逻辑提取为独立的辅助函数,例如 isArmAsset, isX64Asset, is32BitAsset。这样可以让代码更清晰,也更容易在未来进行修改。


if (targetArch === "arm64") {
return isArmAsset;
Expand Down Expand Up @@ -330,7 +332,7 @@ const recommendedAssets = computed(() => {
if (dmg) result.push(dmg);
} else if (p === "linux") {
const appImage = assets.find(
(f) => f.name.toLowerCase().endsWith(".appimage") && isArchCompatible(f.name, arch),
(f) => f.name.endsWith(".AppImage") && isArchCompatible(f.name, arch),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

使用 endsWith('.AppImage') 会进行区分大小写的比较。虽然目前发布的文件名可能是固定的,但为了增加代码的健壮性,建议使用不区分大小写的匹配方式,以防未来文件名大小写发生变化。

可以考虑使用正则表达式,这与文件中其他地方(如369行)的做法一致。

      (f) => /\.appimage$/i.test(f.name) && isArchCompatible(f.name, arch),

);
const deb = assets.find((f) => f.name.endsWith(".deb") && isArchCompatible(f.name, arch));

Expand Down Expand Up @@ -404,23 +406,23 @@ const classifiedAssets = computed<PlatformGroup[]>(() => {
icon: "🐧",
groups: [
{
title: "通用运行包",
desc: "AppImage",
assets: sortAssets(rawAssets.filter((f) => f.name.endsWith(".appimage"))),
title: "AppImage",
desc: "通用运行包",
assets: sortAssets(rawAssets.filter((f) => f.name.endsWith(".AppImage"))),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

同样,这里也建议使用不区分大小写的匹配方式来查找 .AppImage 文件,以提高代码的健壮性。

          assets: sortAssets(rawAssets.filter((f) => /\.appimage$/i.test(f.name))),

},
{
title: "Debian / Ubuntu / Linux Mint...",
desc: "DEB 安装包",
title: "Debian ",
desc: "Debian / Ubuntu / Linux Mint...",
assets: sortAssets(rawAssets.filter((f) => f.name.endsWith(".deb"))),
},
{
title: "RedHat / Fedora / AlmaLinux...",
desc: "RPM 安装包",
title: "RPM 包",
desc: "Red Hat / Fedora / AlmaLinux...",
assets: sortAssets(rawAssets.filter((f) => f.name.endsWith(".rpm"))),
},
{
title: "Arch Linux / Manjaro...",
desc: "Pacman 安装包",
title: "Pacman 包",
desc: "Arch Linux / Manjaro...",
assets: sortAssets(rawAssets.filter((f) => f.name.endsWith(".pacman"))),
},
{
Expand Down