MCPcopy
hub / github.com/AlistGo/alist / EncodePath

Function EncodePath

pkg/utils/path.go:54–75  ·  view source on GitHub ↗
(path string, all ...bool)

Source from the content-addressed store, hash-verified

52}
53
54func EncodePath(path string, all ...bool) string {
55 seg := strings.Split(path, "/")
56 toReplace := []struct {
57 Src string
58 Dst string
59 }{
60 {Src: "%", Dst: "%25"},
61 {"%", "%25"},
62 {"?", "%3F"},
63 {"#", "%23"},
64 }
65 for i := range seg {
66 if len(all) > 0 && all[0] {
67 seg[i] = url.PathEscape(seg[i])
68 } else {
69 for j := range toReplace {
70 seg[i] = strings.ReplaceAll(seg[i], toReplace[j].Src, toReplace[j].Dst)
71 }
72 }
73 }
74 return strings.Join(seg, "/")
75}
76
77func JoinBasePath(basePath, reqPath string) (string, error) {
78 /** relative path:

Callers 15

ExtractMethod · 0.92
ListMethod · 0.92
linkMethod · 0.92
extractMethod · 0.92
GetMetaUrlMethod · 0.92
getProxyLinkMethod · 0.92
FileInfoToObjMethod · 0.92
GetMetaUrlMethod · 0.92
buildStrmLineMethod · 0.92
linkRealFileMethod · 0.92
handlePropfindMethod · 0.92
FsArchiveMetaFunction · 0.92

Calls

no outgoing calls

Tested by 1

TestEncodePathFunction · 0.68