chore: move some types to model

This commit is contained in:
Noah Hsu
2022-06-15 18:06:42 +08:00
parent 2cddd3cf2b
commit 979f8383d8
10 changed files with 62 additions and 37 deletions

View File

@ -2,20 +2,20 @@ package fs
import (
"context"
"github.com/alist-org/alist/v3/internal/driver"
stdpath "path"
"time"
"github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/internal/operations"
"github.com/alist-org/alist/v3/pkg/utils"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
stdpath "path"
"time"
)
// List files
// TODO: hide
// TODO: sort
func List(ctx context.Context, path string) ([]driver.FileInfo, error) {
func List(ctx context.Context, path string) ([]model.FileInfo, error) {
account, actualPath, err := operations.GetAccountAndActualPath(path)
virtualFiles := operations.GetAccountVirtualFilesByPath(path)
if err != nil {
@ -40,7 +40,7 @@ func List(ctx context.Context, path string) ([]driver.FileInfo, error) {
return files, nil
}
func Get(ctx context.Context, path string) (driver.FileInfo, error) {
func Get(ctx context.Context, path string) (model.FileInfo, error) {
path = utils.StandardizationPath(path)
// maybe a virtual file
if path != "/" {
@ -67,7 +67,7 @@ func Get(ctx context.Context, path string) (driver.FileInfo, error) {
return operations.Get(ctx, account, actualPath)
}
func Link(ctx context.Context, path string, args driver.LinkArgs) (*driver.Link, error) {
func Link(ctx context.Context, path string, args model.LinkArgs) (*model.Link, error) {
account, actualPath, err := operations.GetAccountAndActualPath(path)
if err != nil {
return nil, errors.WithMessage(err, "failed get account")

View File

@ -2,7 +2,9 @@ package fs
import (
"context"
"github.com/alist-org/alist/v3/internal/driver"
"github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/internal/operations"
"github.com/pkg/errors"
)
@ -39,7 +41,7 @@ func Rename(ctx context.Context, account driver.Driver, srcPath, dstName string)
}
// Copy if in an account, call move method
// TODO: if not, add copy task
// if not, add copy task
func Copy(ctx context.Context, account driver.Driver, srcPath, dstPath string) error {
srcAccount, srcActualPath, err := operations.GetAccountAndActualPath(srcPath)
if err != nil {
@ -49,9 +51,16 @@ func Copy(ctx context.Context, account driver.Driver, srcPath, dstPath string) e
if err != nil {
return errors.WithMessage(err, "failed get dst account")
}
// copy if in an account, just call driver.Copy
if srcAccount.GetAccount() == dstAccount.GetAccount() {
return operations.Copy(ctx, account, srcActualPath, dstActualPath)
}
// not in an account, add copy task
srcFile, err := operations.Get(ctx, srcAccount, srcActualPath)
if srcFile.IsDir() {
// TODO: recursive copy
return nil
}
// TODO: add copy task, maybe like this:
// operations.Link(ctx,srcAccount,srcActualPath,args)
// get a Reader from link
@ -68,7 +77,7 @@ func Remove(ctx context.Context, account driver.Driver, path string) error {
return operations.Remove(ctx, account, actualPath)
}
func Put(ctx context.Context, account driver.Driver, parentPath string, file driver.FileStream) error {
func Put(ctx context.Context, account driver.Driver, parentPath string, file model.FileStreamer) error {
account, actualParentPath, err := operations.GetAccountAndActualPath(parentPath)
if err != nil {
return errors.WithMessage(err, "failed get account")