Skip to content

Commit

Permalink
fix(alias): add api prefix for proxy url (close #4392)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed May 18, 2023
1 parent 63de65b commit 571bcf0
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 13 deletions.
3 changes: 2 additions & 1 deletion drivers/alias/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ func (d *Alias) link(ctx context.Context, dst, sub string, args model.LinkArgs)
}
if common.ShouldProxy(storage, stdpath.Base(sub)) {
return &model.Link{
URL: fmt.Sprintf("/p%s?sign=%s",
URL: fmt.Sprintf("%s/p%s?sign=%s",
common.GetApiUrl(args.HttpReq),
utils.EncodePath(reqPath, true),
sign.Sign(reqPath)),
}, nil
Expand Down
7 changes: 4 additions & 3 deletions internal/model/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ type ListArgs struct {
}

type LinkArgs struct {
IP string
Header http.Header
Type string
IP string
Header http.Header
Type string
HttpReq *http.Request
}

type Link struct {
Expand Down
12 changes: 7 additions & 5 deletions server/handles/down.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ func Down(c *gin.Context) {
return
} else {
link, _, err := fs.Link(c, rawPath, model.LinkArgs{
IP: c.ClientIP(),
Header: c.Request.Header,
Type: c.Query("type"),
IP: c.ClientIP(),
Header: c.Request.Header,
Type: c.Query("type"),
HttpReq: c.Request,
})
if err != nil {
common.ErrorResp(c, err, 500)
Expand Down Expand Up @@ -84,8 +85,9 @@ func Proxy(c *gin.Context) {
}
}
link, file, err := fs.Link(c, rawPath, model.LinkArgs{
Header: c.Request.Header,
Type: c.Query("type"),
Header: c.Request.Header,
Type: c.Query("type"),
HttpReq: c.Request,
})
if err != nil {
common.ErrorResp(c, err, 500)
Expand Down
2 changes: 1 addition & 1 deletion server/handles/fsmanage.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ func Link(c *gin.Context) {
})
return
}
link, _, err := fs.Link(c, rawPath, model.LinkArgs{IP: c.ClientIP()})
link, _, err := fs.Link(c, rawPath, model.LinkArgs{IP: c.ClientIP(), HttpReq: c.Request})
if err != nil {
common.ErrorResp(c, err, 500)
return
Expand Down
6 changes: 5 additions & 1 deletion server/handles/fsread.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,11 @@ func FsGet(c *gin.Context) {
rawURL = url
} else {
// if storage is not proxy, use raw url by fs.Link
link, _, err := fs.Link(c, reqPath, model.LinkArgs{IP: c.ClientIP(), Header: c.Request.Header})
link, _, err := fs.Link(c, reqPath, model.LinkArgs{
IP: c.ClientIP(),
Header: c.Request.Header,
HttpReq: c.Request,
})
if err != nil {
common.ErrorResp(c, err, 500)
return
Expand Down
4 changes: 2 additions & 2 deletions server/webdav/webdav.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func (h *Handler) handleGetHeadPost(w http.ResponseWriter, r *http.Request) (sta
storage, _ := fs.GetStorage(reqPath, &fs.GetStoragesArgs{})
downProxyUrl := storage.GetStorage().DownProxyUrl
if storage.GetStorage().WebdavNative() || (storage.GetStorage().WebdavProxy() && downProxyUrl == "") {
link, _, err := fs.Link(ctx, reqPath, model.LinkArgs{Header: r.Header})
link, _, err := fs.Link(ctx, reqPath, model.LinkArgs{Header: r.Header, HttpReq: r})
if err != nil {
return http.StatusInternalServerError, err
}
Expand All @@ -249,7 +249,7 @@ func (h *Handler) handleGetHeadPost(w http.ResponseWriter, r *http.Request) (sta
w.Header().Set("Cache-Control", "max-age=0, no-cache, no-store, must-revalidate")
http.Redirect(w, r, u, http.StatusFound)
} else {
link, _, err := fs.Link(ctx, reqPath, model.LinkArgs{IP: utils.ClientIP(r)})
link, _, err := fs.Link(ctx, reqPath, model.LinkArgs{IP: utils.ClientIP(r), HttpReq: r})
if err != nil {
return http.StatusInternalServerError, err
}
Expand Down

0 comments on commit 571bcf0

Please sign in to comment.