Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alist-org
GitHub Repository: alist-org/alist
Path: blob/main/internal/fs/list.go
1560 views
1
package fs
2
3
import (
4
"context"
5
6
"github.com/alist-org/alist/v3/internal/model"
7
"github.com/alist-org/alist/v3/internal/op"
8
"github.com/alist-org/alist/v3/pkg/utils"
9
"github.com/alist-org/alist/v3/server/common"
10
"github.com/pkg/errors"
11
log "github.com/sirupsen/logrus"
12
)
13
14
// List files
15
func list(ctx context.Context, path string, args *ListArgs) ([]model.Obj, error) {
16
meta, _ := ctx.Value("meta").(*model.Meta)
17
user, _ := ctx.Value("user").(*model.User)
18
virtualFiles := op.GetStorageVirtualFilesByPath(path)
19
storage, actualPath, err := op.GetStorageAndActualPath(path)
20
if err != nil && len(virtualFiles) == 0 {
21
return nil, errors.WithMessage(err, "failed get storage")
22
}
23
24
var _objs []model.Obj
25
if storage != nil {
26
_objs, err = op.List(ctx, storage, actualPath, model.ListArgs{
27
ReqPath: path,
28
Refresh: args.Refresh,
29
})
30
if err != nil {
31
if !args.NoLog {
32
log.Errorf("fs/list: %+v", err)
33
}
34
if len(virtualFiles) == 0 {
35
return nil, errors.WithMessage(err, "failed get objs")
36
}
37
}
38
}
39
40
om := model.NewObjMerge()
41
if whetherHide(user, meta, path) {
42
om.InitHideReg(meta.Hide)
43
}
44
objs := om.Merge(_objs, virtualFiles...)
45
return objs, nil
46
}
47
48
func whetherHide(user *model.User, meta *model.Meta, path string) bool {
49
// if user is nil, don't hide
50
if user == nil {
51
return false
52
}
53
perm := common.MergeRolePermissions(user, path)
54
// if user has see-hides permission, don't hide
55
if common.HasPermission(perm, common.PermSeeHides) {
56
return false
57
}
58
// if meta is nil, don't hide
59
if meta == nil {
60
return false
61
}
62
// if meta.Hide is empty, don't hide
63
if meta.Hide == "" {
64
return false
65
}
66
// if meta doesn't apply to sub_folder, don't hide
67
if !utils.PathEqual(meta.Path, path) && !meta.HSub {
68
return false
69
}
70
// if is guest, hide
71
return true
72
}
73
74