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

This commit is contained in:
Liang Ding 2022-09-27 15:31:48 +08:00
parent 9a931ee8dc
commit afa0290ca5
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
3 changed files with 22 additions and 6 deletions

View file

@ -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);
}

View file

@ -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 = () => {

View file

@ -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
}