Optimize isLocalPath function to improve performance (#13990)

This commit is contained in:
Jeffrey Chen 2025-02-07 16:15:00 +08:00 committed by GitHub
parent 4155d9afdd
commit 1ec54282c7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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);
};
export const pathPosix = () => {