(c *gin.Context)
| 44 | } |
| 45 | |
| 46 | func Proxy(c *gin.Context) { |
| 47 | rawPath := c.Request.Context().Value(conf.PathKey).(string) |
| 48 | filename := stdpath.Base(rawPath) |
| 49 | storage, err := fs.GetStorage(rawPath, &fs.GetStoragesArgs{}) |
| 50 | if err != nil { |
| 51 | common.ErrorPage(c, err, 500) |
| 52 | return |
| 53 | } |
| 54 | if canProxy(storage, filename) { |
| 55 | if _, ok := c.GetQuery("d"); !ok { |
| 56 | if url := common.GenerateDownProxyURL(storage.GetStorage(), rawPath); url != "" { |
| 57 | c.Redirect(302, url) |
| 58 | return |
| 59 | } |
| 60 | } |
| 61 | link, file, err := fs.Link(c.Request.Context(), rawPath, model.LinkArgs{ |
| 62 | Header: c.Request.Header, |
| 63 | Type: c.Query("type"), |
| 64 | }) |
| 65 | if err != nil { |
| 66 | common.ErrorPage(c, err, 500) |
| 67 | return |
| 68 | } |
| 69 | proxy(c, link, file, storage.GetStorage().ProxyRange) |
| 70 | } else { |
| 71 | common.ErrorPage(c, errors.New("proxy not allowed"), 403) |
| 72 | return |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | func redirect(c *gin.Context, link *model.Link) { |
| 77 | defer link.Close() |
no test coverage detected