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

Function FsGet

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

Source from the content-addressed store, hash-verified

281}
282
283func FsGet(c *gin.Context, req *FsGetReq, user *model.User) {
284 reqPath, err := user.JoinPath(req.Path)
285 if err != nil {
286 common.ErrorResp(c, err, 403)
287 return
288 }
289 meta, err := op.GetNearestMeta(reqPath)
290 if err != nil && !errors.Is(errors.Cause(err), errs.MetaNotFound) {
291 common.ErrorResp(c, err, 500, true)
292 return
293 }
294 common.GinAppendValues(c, conf.MetaKey, meta)
295 if !common.CanAccess(user, meta, reqPath, req.Password) {
296 common.ErrorStrResp(c, "password is incorrect or you have no permission", 403)
297 return
298 }
299 obj, err := fs.Get(c.Request.Context(), reqPath, &fs.GetArgs{
300 WithStorageDetails: !user.IsGuest() && !setting.GetBool(conf.HideStorageDetails),
301 })
302 if err != nil {
303 common.ErrorResp(c, err, 500)
304 return
305 }
306 var rawURL string
307
308 storage, err := fs.GetStorage(reqPath, &fs.GetStoragesArgs{})
309 provider, ok := model.GetProvider(obj)
310 if !ok && err == nil {
311 provider = storage.Config().Name
312 }
313 if !obj.IsDir() {
314 if err != nil {
315 common.ErrorResp(c, err, 500)
316 return
317 }
318 if storage.Config().MustProxy() || storage.GetStorage().WebProxy {
319 rawURL = common.GenerateDownProxyURL(storage.GetStorage(), reqPath)
320 if rawURL == "" {
321 query := ""
322 if isEncrypt(meta, reqPath) || setting.GetBool(conf.SignAll) {
323 query = "?sign=" + sign.Sign(reqPath)
324 }
325 rawURL = fmt.Sprintf("%s/p%s%s",
326 common.GetApiUrl(c),
327 utils.EncodePath(reqPath, true),
328 query)
329 }
330 } else {
331 // file have raw url
332 if url, ok := model.GetUrl(obj); ok {
333 rawURL = url
334 } else {
335 // if storage is not proxy, use raw url by fs.Link
336 link, _, err := fs.Link(c.Request.Context(), reqPath, model.LinkArgs{
337 IP: c.ClientIP(),
338 Header: c.Request.Header,
339 Redirect: true,
340 })

Callers 1

FsGetSplitFunction · 0.85

Calls 15

ErrorRespFunction · 0.92
GetNearestMetaFunction · 0.92
GinAppendValuesFunction · 0.92
CanAccessFunction · 0.92
ErrorStrRespFunction · 0.92
GetFunction · 0.92
GetBoolFunction · 0.92
GetStorageFunction · 0.92
GetProviderFunction · 0.92
GenerateDownProxyURLFunction · 0.92
SignFunction · 0.92
GetApiUrlFunction · 0.92

Tested by

no test coverage detected