fix: hide objs if only virtual files

pull/1831/head
Noah Hsu 2022-09-17 15:31:30 +08:00
parent d329df70f3
commit bec3a327a7
1 changed files with 24 additions and 18 deletions

View File

@ -16,37 +16,43 @@ import (
func list(ctx context.Context, path string, refresh ...bool) ([]model.Obj, error) { func list(ctx context.Context, path string, refresh ...bool) ([]model.Obj, error) {
meta := ctx.Value("meta").(*model.Meta) meta := ctx.Value("meta").(*model.Meta)
user := ctx.Value("user").(*model.User) user := ctx.Value("user").(*model.User)
var objs []model.Obj
storage, actualPath, err := op.GetStorageAndActualPath(path) storage, actualPath, err := op.GetStorageAndActualPath(path)
virtualFiles := op.GetStorageVirtualFilesByPath(path) virtualFiles := op.GetStorageVirtualFilesByPath(path)
if err != nil { if err != nil {
if len(virtualFiles) != 0 { if len(virtualFiles) == 0 {
return virtualFiles, nil return nil, errors.WithMessage(err, "failed get storage")
} }
return nil, errors.WithMessage(err, "failed get storage") } else {
} objs, err = op.List(ctx, storage, actualPath, model.ListArgs{
objs, err := op.List(ctx, storage, actualPath, model.ListArgs{ ReqPath: path,
ReqPath: path, }, refresh...)
}, refresh...) if err != nil {
if err != nil { log.Errorf("%+v", err)
log.Errorf("%+v", err) if len(virtualFiles) == 0 {
if len(virtualFiles) != 0 { return nil, errors.WithMessage(err, "failed get objs")
return virtualFiles, nil }
} }
return nil, errors.WithMessage(err, "failed get objs")
} }
for _, storageFile := range virtualFiles { if objs == nil {
if !containsByName(objs, storageFile) { objs = virtualFiles
objs = append(objs, storageFile) } else {
for _, storageFile := range virtualFiles {
if !containsByName(objs, storageFile) {
objs = append(objs, storageFile)
}
} }
} }
if whetherHide(user, meta, path) { if whetherHide(user, meta, path) {
objs = hide(objs, meta) objs = hide(objs, meta)
} }
// sort objs // sort objs
if storage.Config().LocalSort { if storage != nil {
model.SortFiles(objs, storage.GetStorage().OrderBy, storage.GetStorage().OrderDirection) if storage.Config().LocalSort {
model.SortFiles(objs, storage.GetStorage().OrderBy, storage.GetStorage().OrderDirection)
}
model.ExtractFolder(objs, storage.GetStorage().ExtractFolder)
} }
model.ExtractFolder(objs, storage.GetStorage().ExtractFolder)
return objs, nil return objs, nil
} }