2022-06-23 15:03:11 +00:00
|
|
|
package fs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-08-03 06:26:59 +00:00
|
|
|
|
2022-06-23 15:03:11 +00:00
|
|
|
"github.com/alist-org/alist/v3/internal/model"
|
2022-08-31 13:01:15 +00:00
|
|
|
"github.com/alist-org/alist/v3/internal/op"
|
2022-06-27 11:10:02 +00:00
|
|
|
"github.com/alist-org/alist/v3/pkg/utils"
|
2022-06-23 15:03:11 +00:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
|
|
|
// List files
|
2022-08-29 11:15:52 +00:00
|
|
|
func list(ctx context.Context, path string, refresh ...bool) ([]model.Obj, error) {
|
2022-06-27 11:51:23 +00:00
|
|
|
meta := ctx.Value("meta").(*model.Meta)
|
2022-06-27 11:10:02 +00:00
|
|
|
user := ctx.Value("user").(*model.User)
|
2022-08-31 13:01:15 +00:00
|
|
|
virtualFiles := op.GetStorageVirtualFilesByPath(path)
|
2022-12-18 11:51:20 +00:00
|
|
|
storage, actualPath, err := op.GetStorageAndActualPath(path)
|
|
|
|
if err != nil && len(virtualFiles) == 0 {
|
|
|
|
return nil, errors.WithMessage(err, "failed get storage")
|
|
|
|
}
|
|
|
|
|
|
|
|
var _objs []model.Obj
|
|
|
|
if storage != nil {
|
|
|
|
_objs, err = op.List(ctx, storage, actualPath, model.ListArgs{
|
2023-01-16 12:02:30 +00:00
|
|
|
ReqPath: path,
|
2022-09-17 07:31:30 +00:00
|
|
|
}, refresh...)
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("%+v", err)
|
|
|
|
if len(virtualFiles) == 0 {
|
|
|
|
return nil, errors.WithMessage(err, "failed get objs")
|
|
|
|
}
|
2022-06-23 15:03:11 +00:00
|
|
|
}
|
|
|
|
}
|
2022-12-18 11:51:20 +00:00
|
|
|
|
|
|
|
om := model.NewObjMerge()
|
2022-06-27 11:10:02 +00:00
|
|
|
if whetherHide(user, meta, path) {
|
2022-12-18 11:51:20 +00:00
|
|
|
om.InitHideReg(meta.Hide)
|
2022-06-27 11:10:02 +00:00
|
|
|
}
|
2023-01-18 02:23:54 +00:00
|
|
|
objs := om.Merge(_objs, virtualFiles...)
|
2022-06-27 11:10:02 +00:00
|
|
|
return objs, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func whetherHide(user *model.User, meta *model.Meta, path string) bool {
|
|
|
|
// if is admin, don't hide
|
2022-06-30 08:09:06 +00:00
|
|
|
if user.CanSeeHides() {
|
2022-06-27 11:10:02 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
// if meta is nil, don't hide
|
|
|
|
if meta == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
// if meta.Hide is empty, don't hide
|
|
|
|
if meta.Hide == "" {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
// if meta doesn't apply to sub_folder, don't hide
|
2022-06-30 07:41:58 +00:00
|
|
|
if !utils.PathEqual(meta.Path, path) && !meta.HSub {
|
2022-06-27 11:10:02 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
// if is guest, hide
|
2022-06-30 08:09:06 +00:00
|
|
|
return true
|
2022-06-27 11:10:02 +00:00
|
|
|
}
|