From 354dee67dc18e0b2b5c175303b33ba4e05b8ceab Mon Sep 17 00:00:00 2001 From: Noah Hsu Date: Fri, 10 Jun 2022 17:26:43 +0800 Subject: [PATCH] feat(fs): get file object --- internal/{operations => fs}/fsutil.go | 2 +- internal/fs/get.go | 16 ++++++++++++++++ internal/{operations/fs.go => fs/list.go} | 11 ++++++++--- 3 files changed, 25 insertions(+), 4 deletions(-) rename internal/{operations => fs}/fsutil.go (92%) create mode 100644 internal/fs/get.go rename internal/{operations/fs.go => fs/list.go} (71%) diff --git a/internal/operations/fsutil.go b/internal/fs/fsutil.go similarity index 92% rename from internal/operations/fsutil.go rename to internal/fs/fsutil.go index 94ed3d195cb..5f46cb7c550 100644 --- a/internal/operations/fsutil.go +++ b/internal/fs/fsutil.go @@ -1,4 +1,4 @@ -package operations +package fs import ( "github.com/alist-org/alist/v3/internal/driver" diff --git a/internal/fs/get.go b/internal/fs/get.go new file mode 100644 index 00000000000..f6274b3a9c4 --- /dev/null +++ b/internal/fs/get.go @@ -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) +} diff --git a/internal/operations/fs.go b/internal/fs/list.go similarity index 71% rename from internal/operations/fs.go rename to internal/fs/list.go index c1089cafabf..369b3c6d8be 100644 --- a/internal/operations/fs.go +++ b/internal/fs/list.go @@ -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