-
-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
73 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,33 @@ | ||
package operations | ||
|
||
import ( | ||
"context" | ||
"github.com/alist-org/alist/v3/internal/driver" | ||
"github.com/pkg/errors" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
func List(ctx context.Context, path string) ([]driver.FileInfo, error) { | ||
account, actualPath, err := GetAccountAndActualPath(path) | ||
virtualFiles := GetAccountVirtualFilesByPath(path) | ||
if err != nil { | ||
if len(virtualFiles) != 0 { | ||
return virtualFiles, nil | ||
} | ||
return nil, errors.WithMessage(err, "failed get account") | ||
} | ||
files, err := account.List(ctx, actualPath) | ||
if err != nil { | ||
log.Errorf("%+v", err) | ||
if len(virtualFiles) != 0 { | ||
return virtualFiles, nil | ||
} | ||
return nil, errors.WithMessage(err, "failed get files") | ||
} | ||
for _, accountFile := range virtualFiles { | ||
if !containsByName(files, accountFile) { | ||
files = append(files, accountFile) | ||
} | ||
} | ||
return files, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package operations | ||
|
||
import ( | ||
"github.com/alist-org/alist/v3/internal/driver" | ||
) | ||
|
||
func containsByName(files []driver.FileInfo, file driver.FileInfo) bool { | ||
for _, f := range files { | ||
if f.GetName() == file.GetName() { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
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" | ||
"strings" | ||
) | ||
|
||
// 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) | ||
if account == nil { | ||
return nil, "", errors.Errorf("can't find account with path: %s", path) | ||
} | ||
log.Debugln("use account: ", account.GetAccount().VirtualPath) | ||
virtualPath := utils.GetActualVirtualPath(account.GetAccount().VirtualPath) | ||
actualPath := utils.StandardizationPath(strings.TrimPrefix(path, virtualPath)) | ||
return account, actualPath, nil | ||
} |