feat: add root prefix before operate
This commit is contained in:
18
internal/operations/fs.go
Normal file
18
internal/operations/fs.go
Normal file
@ -0,0 +1,18 @@
|
||||
package operations
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/alist-org/alist/v3/internal/driver"
|
||||
)
|
||||
|
||||
// In order to facilitate adding some other things before and after file operations
|
||||
|
||||
// List files in storage, not contains virtual file
|
||||
// TODO: cache, and prevent cache breakdown
|
||||
func List(ctx context.Context, account driver.Driver, path string) ([]driver.FileInfo, error) {
|
||||
return account.List(ctx, path)
|
||||
}
|
||||
|
||||
func Get(ctx context.Context, account driver.Driver, path string) (driver.FileInfo, error) {
|
||||
return account.Get(ctx, path)
|
||||
}
|
@ -5,18 +5,27 @@ import (
|
||||
"github.com/alist-org/alist/v3/pkg/utils"
|
||||
"github.com/pkg/errors"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"path"
|
||||
"strings"
|
||||
)
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
// GetAccountAndActualPath Get the corresponding account, and remove the virtual path prefix in path
|
||||
func GetAccountAndActualPath(path string) (driver.Driver, string, error) {
|
||||
path = utils.StandardizationPath(path)
|
||||
account := GetBalancedAccount(path)
|
||||
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 path: %s", path)
|
||||
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 := utils.StandardizationPath(strings.TrimPrefix(path, virtualPath))
|
||||
actualPath := strings.TrimPrefix(rawPath, virtualPath)
|
||||
actualPath = ActualPath(account.GetAddition(), actualPath)
|
||||
return account, actualPath, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user