Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alist-org
GitHub Repository: alist-org/alist
Path: blob/main/drivers/crypt/util.go
1987 views
1
package crypt
2
3
import (
4
stdpath "path"
5
"path/filepath"
6
"strings"
7
8
"github.com/alist-org/alist/v3/internal/op"
9
)
10
11
// will give the best guessing based on the path
12
func guessPath(path string) (isFolder, secondTry bool) {
13
if strings.HasSuffix(path, "/") {
14
//confirmed a folder
15
return true, false
16
}
17
lastSlash := strings.LastIndex(path, "/")
18
if strings.Index(path[lastSlash:], ".") < 0 {
19
//no dot, try folder then try file
20
return true, true
21
}
22
return false, true
23
}
24
25
func (d *Crypt) getPathForRemote(path string, isFolder bool) (remoteFullPath string) {
26
if isFolder && !strings.HasSuffix(path, "/") {
27
path = path + "/"
28
}
29
dir, fileName := filepath.Split(path)
30
31
remoteDir := d.cipher.EncryptDirName(dir)
32
remoteFileName := ""
33
if len(strings.TrimSpace(fileName)) > 0 {
34
remoteFileName = d.cipher.EncryptFileName(fileName)
35
}
36
return stdpath.Join(d.RemotePath, remoteDir, remoteFileName)
37
38
}
39
40
// actual path is used for internal only. any link for user should come from remoteFullPath
41
func (d *Crypt) getActualPathForRemote(path string, isFolder bool) (string, error) {
42
_, remoteActualPath, err := op.GetStorageAndActualPath(d.getPathForRemote(path, isFolder))
43
return remoteActualPath, err
44
}
45
46