Bläddra i källkod

:art: 超链接地址更好地兼容本地路径 https://github.com/siyuan-note/siyuan/issues/5980

Liang Ding 2 år sedan
förälder
incheckning
afa0290ca5
3 ändrade filer med 22 tillägg och 6 borttagningar
  1. 5 3
      app/src/editor/util.ts
  2. 13 2
      app/src/util/pathName.ts
  3. 4 1
      kernel/model/upload.go

+ 5 - 3
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);
     }

+ 13 - 2
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 = () => {

+ 4 - 1
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
 		}