mirror of https://github.com/Xhofe/alist
feat: get root folder file
parent
3135775250
commit
3e8f36e9f3
|
@ -3,10 +3,13 @@ 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/alist-org/alist/v3/pkg/utils"
|
||||
"github.com/pkg/errors"
|
||||
log "github.com/sirupsen/logrus"
|
||||
stdpath "path"
|
||||
"time"
|
||||
)
|
||||
|
||||
// List files
|
||||
|
@ -38,14 +41,27 @@ func List(ctx context.Context, path string) ([]driver.FileInfo, error) {
|
|||
}
|
||||
|
||||
func Get(ctx context.Context, path string) (driver.FileInfo, error) {
|
||||
virtualFiles := operations.GetAccountVirtualFilesByPath(path)
|
||||
for _, f := range virtualFiles {
|
||||
if f.GetName() == stdpath.Base(path) {
|
||||
return f, nil
|
||||
path = utils.StandardizationPath(path)
|
||||
// maybe a virtual file
|
||||
if path != "/" {
|
||||
virtualFiles := operations.GetAccountVirtualFilesByPath(stdpath.Dir(path))
|
||||
for _, f := range virtualFiles {
|
||||
if f.GetName() == stdpath.Base(path) {
|
||||
return f, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
account, actualPath, err := operations.GetAccountAndActualPath(path)
|
||||
if err != nil {
|
||||
// if there are no account prefix with path, maybe root folder
|
||||
if path == "/" {
|
||||
return model.File{
|
||||
Name: "root",
|
||||
Size: 0,
|
||||
Modified: time.Time{},
|
||||
IsFolder: true,
|
||||
}, nil
|
||||
}
|
||||
return nil, errors.WithMessage(err, "failed get account")
|
||||
}
|
||||
return operations.Get(ctx, account, actualPath)
|
||||
|
|
|
@ -11,6 +11,7 @@ func StandardizationPath(path string) string {
|
|||
return path
|
||||
}
|
||||
|
||||
// PathEqual judge path is equal
|
||||
func PathEqual(path1, path2 string) bool {
|
||||
return StandardizationPath(path1) == StandardizationPath(path2)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue