feat(fs): get file object

refactor/fs
Noah Hsu 2022-06-10 17:26:43 +08:00
parent 122b7baa73
commit 354dee67dc
3 changed files with 25 additions and 4 deletions

View File

@ -1,4 +1,4 @@
package operations
package fs
import (
"github.com/alist-org/alist/v3/internal/driver"

16
internal/fs/get.go Normal file
View File

@ -0,0 +1,16 @@
package fs
import (
"context"
"github.com/alist-org/alist/v3/internal/driver"
"github.com/alist-org/alist/v3/internal/operations"
"github.com/pkg/errors"
)
func Get(ctx context.Context, path string) (driver.FileInfo, error) {
account, actualPath, err := operations.GetAccountAndActualPath(path)
if err != nil {
return nil, errors.WithMessage(err, "failed get account")
}
return account.File(ctx, actualPath)
}

View File

@ -1,15 +1,20 @@
package operations
package fs
import (
"context"
"github.com/alist-org/alist/v3/internal/driver"
"github.com/alist-org/alist/v3/internal/operations"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
)
// List files
// TODO: hide
// TODO: sort
// TODO: cache, and prevent cache breakdown
func List(ctx context.Context, path string) ([]driver.FileInfo, error) {
account, actualPath, err := GetAccountAndActualPath(path)
virtualFiles := GetAccountVirtualFilesByPath(path)
account, actualPath, err := operations.GetAccountAndActualPath(path)
virtualFiles := operations.GetAccountVirtualFilesByPath(path)
if err != nil {
if len(virtualFiles) != 0 {
return virtualFiles, nil