(c *gin.Context, req *FsGetReq, user *model.User)
| 281 | } |
| 282 | |
| 283 | func 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 | }) |
no test coverage detected