MCPcopy
hub / github.com/OpenListTeam/OpenList / urlTreeSplitLineFormPath

Function urlTreeSplitLineFormPath

internal/op/path.go:34–58  ·  view source on GitHub ↗

urlTreeSplitLineFormPath 分割path中分割真实路径和UrlTree定义字符串

(path string)

Source from the content-addressed store, hash-verified

32
33// urlTreeSplitLineFormPath 分割path中分割真实路径和UrlTree定义字符串
34func urlTreeSplitLineFormPath(path string) (pp string, file string) {
35 // url.PathUnescape 会移除 // ,手动加回去
36 path = strings.Replace(path, "https:/", "https://", 1)
37 path = strings.Replace(path, "http:/", "http://", 1)
38 if strings.Contains(path, ":https:/") || strings.Contains(path, ":http:/") {
39 // URL-Tree模式 /url_tree_drivr/file_name[:size[:time]]:https://example.com/file
40 fPath := strings.SplitN(path, ":", 2)[0]
41 pp, _ = stdpath.Split(fPath)
42 file = path[len(pp):]
43 } else if strings.Contains(path, "/https:/") || strings.Contains(path, "/http:/") {
44 // URL-Tree模式 /url_tree_drivr/https://example.com/file
45 index := strings.Index(path, "/http://")
46 if index == -1 {
47 index = strings.Index(path, "/https://")
48 }
49 pp = path[:index]
50 file = path[index+1:]
51 } else {
52 pp, file = stdpath.Split(path)
53 }
54 if pp == "" {
55 pp = "/"
56 }
57 return
58}

Callers 1

PutFunction · 0.85

Calls 1

IndexMethod · 0.65

Tested by

no test coverage detected