From 78a9676c7cdd282b68f27acdd2a095df427aa228 Mon Sep 17 00:00:00 2001 From: Sakura-Byte <42319937+Sakura-Byte@users.noreply.github.com> Date: Sun, 12 May 2024 17:34:36 +0800 Subject: [PATCH] feat(alist_v3): Optional pass UA to upstream remote (#6443) * fix(115): Support 115 302 redirect while getting link under (nested) alist_v3 remote * chore: simplify logic * chore: simplify logic * use internal UA * add option to set if the user want their ua be passed to upstream --- drivers/alist_v3/driver.go | 10 +++++++++- drivers/alist_v3/meta.go | 11 ++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/alist_v3/driver.go b/drivers/alist_v3/driver.go index f46e68d07a4..53fb93caa1f 100644 --- a/drivers/alist_v3/driver.go +++ b/drivers/alist_v3/driver.go @@ -109,11 +109,19 @@ func (d *AListV3) List(ctx context.Context, dir model.Obj, args model.ListArgs) func (d *AListV3) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (*model.Link, error) { var resp common.Resp[FsGetResp] + // if PassUAToUpsteam is true, then pass the user-agent to the upstream + userAgent := base.UserAgent + if d.PassUAToUpsteam { + userAgent = args.Header.Get("user-agent") + if userAgent == "" { + userAgent = base.UserAgent + } + } _, err := d.request("/fs/get", http.MethodPost, func(req *resty.Request) { req.SetResult(&resp).SetBody(FsGetReq{ Path: file.GetPath(), Password: d.MetaPassword, - }) + }).SetHeader("user-agent", userAgent) }) if err != nil { return nil, err diff --git a/drivers/alist_v3/meta.go b/drivers/alist_v3/meta.go index bb3d35aea22..c04c737b149 100644 --- a/drivers/alist_v3/meta.go +++ b/drivers/alist_v3/meta.go @@ -7,11 +7,12 @@ import ( type Addition struct { driver.RootPath - Address string `json:"url" required:"true"` - MetaPassword string `json:"meta_password"` - Username string `json:"username"` - Password string `json:"password"` - Token string `json:"token"` + Address string `json:"url" required:"true"` + MetaPassword string `json:"meta_password"` + Username string `json:"username"` + Password string `json:"password"` + Token string `json:"token"` + PassUAToUpsteam bool `json:"pass_ua_to_upsteam" default:"true"` } var config = driver.Config{