MCPcopy Index your code
hub / github.com/OpenListTeam/OpenList / List

Method List

drivers/crypt/driver.go:102–167  ·  view source on GitHub ↗
(ctx context.Context, dir model.Obj, args model.ListArgs)

Source from the content-addressed store, hash-verified

100}
101
102func (d *Crypt) List(ctx context.Context, dir model.Obj, args model.ListArgs) ([]model.Obj, error) {
103 remoteFullPath := dir.GetPath()
104 objs, err := fs.List(ctx, remoteFullPath, &fs.ListArgs{NoLog: true, Refresh: args.Refresh})
105 // the obj must implement the model.SetPath interface
106 // return objs, err
107 if err != nil {
108 return nil, err
109 }
110
111 result := make([]model.Obj, 0, len(objs))
112 for _, obj := range objs {
113 size := obj.GetSize()
114 mask := model.GetObjMask(obj)
115 name := obj.GetName()
116 if mask&model.Virtual == 0 {
117 if obj.IsDir() {
118 name, err = d.cipher.DecryptDirName(model.UnwrapObjName(obj).GetName())
119 if err != nil {
120 // filter illegal files
121 continue
122 }
123 } else {
124 size, err = d.cipher.DecryptedSize(size)
125 if err != nil {
126 // filter illegal files
127 continue
128 }
129 name, err = d.cipher.DecryptFileName(model.UnwrapObjName(obj).GetName())
130 if err != nil {
131 // filter illegal files
132 continue
133 }
134 }
135 }
136 if !d.ShowHidden && strings.HasPrefix(name, ".") {
137 continue
138 }
139 objRes := &model.Object{
140 Path: stdpath.Join(remoteFullPath, obj.GetName()),
141 Name: name,
142 Size: size,
143 Modified: obj.ModTime(),
144 IsFolder: obj.IsDir(),
145 Ctime: obj.CreateTime(),
146 Mask: mask &^ model.Temp,
147 // discarding hash as it's encrypted
148 }
149 if !d.Thumbnail || !strings.HasPrefix(args.ReqPath, "/") {
150 result = append(result, objRes)
151 continue
152 }
153 thumbPath := stdpath.Join(args.ReqPath, ".thumbnails", name+".webp")
154 thumb := fmt.Sprintf("%s/d%s?sign=%s",
155 common.GetApiUrl(ctx),
156 utils.EncodePath(thumbPath, true),
157 sign.Sign(thumbPath))
158 result = append(result, &model.ObjThumb{
159 Object: *objRes,

Callers

nothing calls this directly

Calls 12

ListFunction · 0.92
GetObjMaskFunction · 0.92
UnwrapObjNameFunction · 0.92
GetApiUrlFunction · 0.92
EncodePathFunction · 0.92
SignFunction · 0.92
GetPathMethod · 0.65
GetSizeMethod · 0.65
GetNameMethod · 0.65
IsDirMethod · 0.65
ModTimeMethod · 0.65
CreateTimeMethod · 0.65

Tested by

no test coverage detected