Skip to content

Commit

Permalink
refactor: 优化 isLocalPath 函数,提高性能
Browse files Browse the repository at this point in the history
  • Loading branch information
TCOTC committed Feb 1, 2025
1 parent 63ef661 commit 866d14c
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions app/src/util/pathName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,14 @@ export const getAssetName = (assetPath: string) => {
};

export const isLocalPath = (link: string) => {
if (!link) {
link = link?.trim();
if (!link || link.length === 0) {
return false;
}

link = link.trim();
if (1 > link.length) {
return false;
}

link = link.toLowerCase();
if (link.startsWith("assets/") || link.startsWith("file://") || link.startsWith("\\\\") /* Windows 网络共享路径 */) {
return true;
}

const colonIdx = link.indexOf(":");
return 1 === colonIdx; // 冒号前面只有一个字符认为是 Windows 盘符而不是网络协议
// Windows 网络共享路径双斜杠
// 冒号前面只有一个字母认为是 Windows 盘符而不是网络协议
return /^assets\/|file:\/\/|\\\\|[A-Z]:$/i.test(link.slice(0, 7));
};

export const pathPosix = () => {
Expand Down

0 comments on commit 866d14c

Please sign in to comment.