MCPcopy Create free account
hub / github.com/OpenListTeam/OpenList / FsList

Function FsList

server/handles/fsread.go:80–127  ·  view source on GitHub ↗
(c *gin.Context, req *ListReq, user *model.User)

Source from the content-addressed store, hash-verified

78}
79
80func FsList(c *gin.Context, req *ListReq, user *model.User) {
81 reqPath, err := user.JoinPath(req.Path)
82 if err != nil {
83 common.ErrorResp(c, err, 403)
84 return
85 }
86 meta, err := op.GetNearestMeta(reqPath)
87 if err != nil && !errors.Is(errors.Cause(err), errs.MetaNotFound) {
88 common.ErrorResp(c, err, 500, true)
89 return
90 }
91 common.GinAppendValues(c, conf.MetaKey, meta)
92 if !common.CanAccess(user, meta, reqPath, req.Password) {
93 common.ErrorStrResp(c, "password is incorrect or you have no permission", 403)
94 return
95 }
96 canWriteContentAtPath := common.CanWrite(user, meta, reqPath) && (user.CanWriteContent() || common.CanWriteContentBypassUserPerms(meta, reqPath))
97 if req.Refresh && !canWriteContentAtPath {
98 common.ErrorStrResp(c, "Refresh without permission", 403)
99 return
100 }
101 objs, err := fs.List(c.Request.Context(), reqPath, &fs.ListArgs{
102 Refresh: req.Refresh,
103 WithStorageDetails: !user.IsGuest() && !setting.GetBool(conf.HideStorageDetails),
104 })
105 if err != nil {
106 common.ErrorResp(c, err, 500)
107 return
108 }
109 total, objs := pagination(objs, &req.PageReq)
110 provider := "unknown"
111 var directUploadTools []string
112 if canWriteContentAtPath {
113 if storage, err := fs.GetStorage(reqPath, &fs.GetStoragesArgs{}); err == nil {
114 directUploadTools = op.GetDirectUploadTools(storage)
115 }
116 }
117 common.SuccessResp(c, FsListResp{
118 Content: toObjsResp(objs, reqPath, isEncrypt(meta, reqPath)),
119 Total: int64(total),
120 Readme: getReadme(meta, reqPath),
121 Header: getHeader(meta, reqPath),
122 Write: common.CanWrite(user, meta, reqPath),
123 WriteContentBypass: common.CanWriteContentBypassUserPerms(meta, reqPath),
124 Provider: provider,
125 DirectUploadTools: directUploadTools,
126 })
127}
128
129func FsDirs(c *gin.Context) {
130 var req DirReq

Callers 1

FsListSplitFunction · 0.85

Calls 15

ErrorRespFunction · 0.92
GetNearestMetaFunction · 0.92
GinAppendValuesFunction · 0.92
CanAccessFunction · 0.92
ErrorStrRespFunction · 0.92
CanWriteFunction · 0.92
ListFunction · 0.92
GetBoolFunction · 0.92
GetStorageFunction · 0.92
GetDirectUploadToolsFunction · 0.92
SuccessRespFunction · 0.92

Tested by

no test coverage detected