alist/internal/operations/path.go

32 lines
1.1 KiB
Go
Raw Normal View History

2022-06-10 09:18:27 +00:00
package operations
import (
"github.com/alist-org/alist/v3/internal/driver"
"github.com/alist-org/alist/v3/pkg/utils"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
2022-06-10 12:20:45 +00:00
"path"
2022-06-10 09:18:27 +00:00
"strings"
)
2022-06-10 12:20:45 +00:00
func ActualPath(account driver.Additional, rawPath string) string {
if i, ok := account.(driver.IRootFolderPath); ok {
rawPath = path.Join(i.GetRootFolder(), rawPath)
}
return utils.StandardizationPath(rawPath)
}
2022-06-10 09:18:27 +00:00
// GetAccountAndActualPath Get the corresponding account, and remove the virtual path prefix in path
2022-06-10 12:20:45 +00:00
func GetAccountAndActualPath(rawPath string) (driver.Driver, string, error) {
rawPath = utils.StandardizationPath(rawPath)
account := GetBalancedAccount(rawPath)
2022-06-10 09:18:27 +00:00
if account == nil {
2022-06-10 12:20:45 +00:00
return nil, "", errors.Errorf("can't find account with rawPath: %s", rawPath)
2022-06-10 09:18:27 +00:00
}
log.Debugln("use account: ", account.GetAccount().VirtualPath)
virtualPath := utils.GetActualVirtualPath(account.GetAccount().VirtualPath)
2022-06-10 12:20:45 +00:00
actualPath := strings.TrimPrefix(rawPath, virtualPath)
actualPath = ActualPath(account.GetAddition(), actualPath)
2022-06-10 09:18:27 +00:00
return account, actualPath, nil
}