2022-06-23 23:03:11 +08:00
|
|
|
package fs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-08-03 14:26:59 +08:00
|
|
|
|
2022-06-23 23:03:11 +08:00
|
|
|
"github.com/alist-org/alist/v3/internal/model"
|
2022-08-31 21:01:15 +08:00
|
|
|
"github.com/alist-org/alist/v3/internal/op"
|
2022-06-27 19:10:02 +08:00
|
|
|
"github.com/alist-org/alist/v3/pkg/utils"
|
2022-06-23 23:03:11 +08:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
|
|
|
// List files
|
2023-04-07 00:02:07 +08:00
|
|
|
func list(ctx context.Context, path string, args *ListArgs) ([]model.Obj, error) {
|
2023-05-01 15:44:25 +08:00
|
|
|
meta, _ := ctx.Value("meta").(*model.Meta)
|
|
|
|
user, _ := ctx.Value("user").(*model.User)
|
2022-08-31 21:01:15 +08:00
|
|
|
virtualFiles := op.GetStorageVirtualFilesByPath(path)
|
2022-12-18 19:51:20 +08: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 20:02:30 +08:00
|
|
|
ReqPath: path,
|
2024-06-16 16:59:10 +08:00
|
|
|
Refresh: args.Refresh,
|
|
|
|
})
|
2022-09-17 15:31:30 +08:00
|
|
|
if err != nil {
|
2023-04-09 15:46:26 +08:00
|
|
|
if !args.NoLog {
|
|
|
|
log.Errorf("fs/list: %+v", err)
|
|
|
|
}
|
2022-09-17 15:31:30 +08:00
|
|
|
if len(virtualFiles) == 0 {
|
|
|
|
return nil, errors.WithMessage(err, "failed get objs")
|
|
|
|
}
|
2022-06-23 23:03:11 +08:00
|
|
|
}
|
|
|
|
}
|
2022-12-18 19:51:20 +08:00
|
|
|
|
|
|
|
om := model.NewObjMerge()
|
2022-06-27 19:10:02 +08:00
|
|
|
if whetherHide(user, meta, path) {
|
2022-12-18 19:51:20 +08:00
|
|
|
om.InitHideReg(meta.Hide)
|
2022-06-27 19:10:02 +08:00
|
|
|
}
|
2023-01-18 10:23:54 +08:00
|
|
|
objs := om.Merge(_objs, virtualFiles...)
|
2022-06-27 19:10:02 +08:00
|
|
|
return objs, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func whetherHide(user *model.User, meta *model.Meta, path string) bool {
|
|
|
|
// if is admin, don't hide
|
2023-05-01 15:44:25 +08:00
|
|
|
if user == nil || user.CanSeeHides() {
|
2022-06-27 19:10:02 +08: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 15:41:58 +08:00
|
|
|
if !utils.PathEqual(meta.Path, path) && !meta.HSub {
|
2022-06-27 19:10:02 +08:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
// if is guest, hide
|
2022-06-30 16:09:06 +08:00
|
|
|
return true
|
2022-06-27 19:10:02 +08:00
|
|
|
}
|