diff --git a/drivers/alias/util.go b/drivers/alias/util.go index e6949690..4e3d6bf0 100644 --- a/drivers/alias/util.go +++ b/drivers/alias/util.go @@ -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 diff --git a/internal/model/args.go b/internal/model/args.go index e2310e96..e9c3d12f 100644 --- a/internal/model/args.go +++ b/internal/model/args.go @@ -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 { diff --git a/server/handles/down.go b/server/handles/down.go index 2977769b..5f7b010a 100644 --- a/server/handles/down.go +++ b/server/handles/down.go @@ -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) @@ -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) diff --git a/server/handles/fsmanage.go b/server/handles/fsmanage.go index d8ccb832..c1ea915e 100644 --- a/server/handles/fsmanage.go +++ b/server/handles/fsmanage.go @@ -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 diff --git a/server/handles/fsread.go b/server/handles/fsread.go index 14da6fe0..c21e294b 100644 --- a/server/handles/fsread.go +++ b/server/handles/fsread.go @@ -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 diff --git a/server/webdav/webdav.go b/server/webdav/webdav.go index 83918379..a5b362d6 100644 --- a/server/webdav/webdav.go +++ b/server/webdav/webdav.go @@ -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 } @@ -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 }