mirror of https://github.com/Xhofe/alist
feat: get root folder file
parent
3135775250
commit
3e8f36e9f3
|
@ -3,10 +3,13 @@ package fs
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/alist-org/alist/v3/internal/driver"
|
"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/internal/operations"
|
||||||
|
"github.com/alist-org/alist/v3/pkg/utils"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
stdpath "path"
|
stdpath "path"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// List files
|
// 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) {
|
func Get(ctx context.Context, path string) (driver.FileInfo, error) {
|
||||||
virtualFiles := operations.GetAccountVirtualFilesByPath(path)
|
path = utils.StandardizationPath(path)
|
||||||
for _, f := range virtualFiles {
|
// maybe a virtual file
|
||||||
if f.GetName() == stdpath.Base(path) {
|
if path != "/" {
|
||||||
return f, nil
|
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)
|
account, actualPath, err := operations.GetAccountAndActualPath(path)
|
||||||
if err != nil {
|
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 nil, errors.WithMessage(err, "failed get account")
|
||||||
}
|
}
|
||||||
return operations.Get(ctx, account, actualPath)
|
return operations.Get(ctx, account, actualPath)
|
||||||
|
|
|
@ -11,6 +11,7 @@ func StandardizationPath(path string) string {
|
||||||
return path
|
return path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PathEqual judge path is equal
|
||||||
func PathEqual(path1, path2 string) bool {
|
func PathEqual(path1, path2 string) bool {
|
||||||
return StandardizationPath(path1) == StandardizationPath(path2)
|
return StandardizationPath(path1) == StandardizationPath(path2)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue