2022-06-10 09:18:27 +00:00
|
|
|
package operations
|
|
|
|
|
|
|
|
import (
|
2022-06-15 12:31:23 +00:00
|
|
|
stdpath "path"
|
|
|
|
"strings"
|
|
|
|
|
2022-06-10 09:18:27 +00:00
|
|
|
"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
|
|
|
func ActualPath(account driver.Additional, rawPath string) string {
|
|
|
|
if i, ok := account.(driver.IRootFolderPath); ok {
|
2022-06-15 12:31:23 +00:00
|
|
|
rawPath = stdpath.Join(i.GetRootFolderPath(), rawPath)
|
2022-06-10 12:20:45 +00:00
|
|
|
}
|
|
|
|
return utils.StandardizationPath(rawPath)
|
|
|
|
}
|
|
|
|
|
2022-06-15 12:31:23 +00:00
|
|
|
// GetAccountAndActualPath Get the corresponding account
|
|
|
|
// for path: remove the virtual path prefix and join the actual root folder if exists
|
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
|
|
|
|
}
|