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

Function Proxy

server/handles/down.go:46–74  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

44}
45
46func 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
76func redirect(c *gin.Context, link *model.Link) {
77 defer link.Close()

Callers 1

DownFunction · 0.70

Calls 7

GetStorageFunction · 0.92
ErrorPageFunction · 0.92
GenerateDownProxyURLFunction · 0.92
LinkFunction · 0.92
canProxyFunction · 0.85
proxyFunction · 0.85
GetStorageMethod · 0.65

Tested by

no test coverage detected