From afa0290ca55f44118acdba3f7c5039eac6242087 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Tue, 27 Sep 2022 15:31:48 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E8=B6=85=E9=93=BE=E6=8E=A5=E5=9C=B0?= =?UTF-8?q?=E5=9D=80=E6=9B=B4=E5=A5=BD=E5=9C=B0=E5=85=BC=E5=AE=B9=E6=9C=AC?= =?UTF-8?q?=E5=9C=B0=E8=B7=AF=E5=BE=84=20https://github.com/siyuan-note/si?= =?UTF-8?q?yuan/issues/5980?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/editor/util.ts | 8 +++++--- app/src/util/pathName.ts | 15 +++++++++++++-- kernel/model/upload.go | 5 ++++- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/app/src/editor/util.ts b/app/src/editor/util.ts index 51b44fd8c..6a5c09936 100644 --- a/app/src/editor/util.ts +++ b/app/src/editor/util.ts @@ -472,7 +472,7 @@ export const openBy = (url: string, type: "folder" | "app") => { let address = ""; if ("windows" === window.siyuan.config.system.os) { // `file://` 协议兼容 Window 平台使用 `/` 作为目录分割线 https://github.com/siyuan-note/siyuan/issues/5681 - address = url.replace("file:///", "").replace("file://\\", "").replace("file://", "").replace("/", "\\"); + address = url.replace("file:///", "").replace("file://\\", "").replace("file://", "").replace(/\//g, "\\"); } else { address = url.replace("file://", ""); } @@ -482,8 +482,10 @@ export const openBy = (url: string, type: "folder" | "app") => { shell.openPath(address); } else if (type === "folder") { if ("windows" === window.siyuan.config.system.os) { - // Windows 端打开本地文件所在位置失效 https://github.com/siyuan-note/siyuan/issues/5808 - address = address.replace(/\\\\/g, "\\"); + if (!address.startsWith("\\\\")) { // \\ 开头的路径是 Windows 网络共享路径 https://github.com/siyuan-note/siyuan/issues/5980 + // Windows 端打开本地文件所在位置失效 https://github.com/siyuan-note/siyuan/issues/5808 + address = address.replace(/\\\\/g, "\\"); + } } shell.showItemInFolder(address); } diff --git a/app/src/util/pathName.ts b/app/src/util/pathName.ts index 5e0aaaf9d..758744728 100644 --- a/app/src/util/pathName.ts +++ b/app/src/util/pathName.ts @@ -37,8 +37,19 @@ export const isLocalPath = (link: string) => { if (!link) { return false; } - return link.startsWith("assets/") || link.startsWith("file://") || - 0 < link.indexOf(":/") || link.startsWith("\\\\"); // 超链接地址更好地兼容本地路径 https://github.com/siyuan-note/siyuan/issues/5980 + + 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 盘符而不是网络协议 }; export const pathPosix = () => { diff --git a/kernel/model/upload.go b/kernel/model/upload.go index 12ffb93a4..5c2c4f3d0 100644 --- a/kernel/model/upload.go +++ b/kernel/model/upload.go @@ -60,7 +60,10 @@ func InsertLocalAssets(id string, assetPaths []string, isUpload bool) (succMap m fName += ext baseName := fName if gulu.File.IsDir(p) || !isUpload { - succMap[baseName] = "file://" + p + if !strings.HasPrefix(p, "\\\\") { + p = "file://" + p + } + succMap[baseName] = p continue }