mirror of https://github.com/Xhofe/alist
34 lines
1.1 KiB
Go
34 lines
1.1 KiB
Go
package operations
|
|
|
|
import (
|
|
stdpath "path"
|
|
"strings"
|
|
|
|
"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"
|
|
)
|
|
|
|
func ActualPath(account driver.Additional, rawPath string) string {
|
|
if i, ok := account.(driver.IRootFolderPath); ok {
|
|
rawPath = stdpath.Join(i.GetRootFolderPath(), rawPath)
|
|
}
|
|
return utils.StandardizationPath(rawPath)
|
|
}
|
|
|
|
// GetAccountAndActualPath Get the corresponding account
|
|
// for path: remove the virtual path prefix and join the actual root folder if exists
|
|
func GetAccountAndActualPath(rawPath string) (driver.Driver, string, error) {
|
|
rawPath = utils.StandardizationPath(rawPath)
|
|
account := GetBalancedAccount(rawPath)
|
|
if account == nil {
|
|
return nil, "", errors.Errorf("can't find account with rawPath: %s", rawPath)
|
|
}
|
|
log.Debugln("use account: ", account.GetAccount().VirtualPath)
|
|
virtualPath := utils.GetActualVirtualPath(account.GetAccount().VirtualPath)
|
|
actualPath := strings.TrimPrefix(rawPath, virtualPath)
|
|
actualPath = ActualPath(account.GetAddition(), actualPath)
|
|
return account, actualPath, nil
|
|
}
|