From 9230c9551a1524e927044484f08f669303d3b87a Mon Sep 17 00:00:00 2001 From: Sakura-Byte <42319937+Sakura-Byte@users.noreply.github.com> Date: Sat, 11 May 2024 20:30:05 +0800 Subject: [PATCH 1/5] fix(115): Support 115 302 redirect while getting link under (nested) alist_v3 remote --- drivers/alist_v3/driver.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/alist_v3/driver.go b/drivers/alist_v3/driver.go index f46e68d07a4..cfa4bd11c84 100644 --- a/drivers/alist_v3/driver.go +++ b/drivers/alist_v3/driver.go @@ -109,11 +109,23 @@ 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] + var oriUa = args.Header.Get("X-Alist-OriUA") + userAgent := oriUa + // if the original UA is empty, then use the UA in the header + // 1st: X-Alist-OriUA + // 2nd: user-agent + // 3rd: default UA + if oriUa == "" { + userAgent = args.Header.Get("user-agent") + if userAgent == "" { + userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36" + } + } _, 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).SetHeader("X-Alist-OriUA", userAgent) }) if err != nil { return nil, err From 1a7f25b1bea24b5a35834c8ab06d7bc2f26df1ab Mon Sep 17 00:00:00 2001 From: Sakura-Byte <42319937+Sakura-Byte@users.noreply.github.com> Date: Sat, 11 May 2024 20:46:58 +0800 Subject: [PATCH 2/5] chore: simplify logic --- drivers/alist_v3/driver.go | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/drivers/alist_v3/driver.go b/drivers/alist_v3/driver.go index cfa4bd11c84..a7cda0d1c0b 100644 --- a/drivers/alist_v3/driver.go +++ b/drivers/alist_v3/driver.go @@ -109,17 +109,9 @@ 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] - var oriUa = args.Header.Get("X-Alist-OriUA") - userAgent := oriUa - // if the original UA is empty, then use the UA in the header - // 1st: X-Alist-OriUA - // 2nd: user-agent - // 3rd: default UA - if oriUa == "" { - userAgent = args.Header.Get("user-agent") - if userAgent == "" { - userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36" - } + userAgent := args.Header.Get("user-agent") + if userAgent == "" { + userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36" } _, err := d.request("/fs/get", http.MethodPost, func(req *resty.Request) { req.SetResult(&resp).SetBody(FsGetReq{ From 211b19fdeb29ca32b6601a1102f50c00ce8ca0d8 Mon Sep 17 00:00:00 2001 From: Sakura-Byte <42319937+Sakura-Byte@users.noreply.github.com> Date: Sat, 11 May 2024 20:47:36 +0800 Subject: [PATCH 3/5] chore: simplify logic --- drivers/alist_v3/driver.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/alist_v3/driver.go b/drivers/alist_v3/driver.go index a7cda0d1c0b..648f398e711 100644 --- a/drivers/alist_v3/driver.go +++ b/drivers/alist_v3/driver.go @@ -117,7 +117,7 @@ func (d *AListV3) Link(ctx context.Context, file model.Obj, args model.LinkArgs) req.SetResult(&resp).SetBody(FsGetReq{ Path: file.GetPath(), Password: d.MetaPassword, - }).SetHeader("user-agent", userAgent).SetHeader("X-Alist-OriUA", userAgent) + }).SetHeader("user-agent", userAgent) }) if err != nil { return nil, err From a8c68a055b3aecc0cfa9468796426de75f868305 Mon Sep 17 00:00:00 2001 From: Sakura-Byte <42319937+Sakura-Byte@users.noreply.github.com> Date: Sat, 11 May 2024 20:56:47 +0800 Subject: [PATCH 4/5] use internal UA --- drivers/alist_v3/driver.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/alist_v3/driver.go b/drivers/alist_v3/driver.go index 648f398e711..bdcd4341e87 100644 --- a/drivers/alist_v3/driver.go +++ b/drivers/alist_v3/driver.go @@ -111,7 +111,7 @@ func (d *AListV3) Link(ctx context.Context, file model.Obj, args model.LinkArgs) var resp common.Resp[FsGetResp] userAgent := args.Header.Get("user-agent") if userAgent == "" { - userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36" + userAgent = base.UserAgent } _, err := d.request("/fs/get", http.MethodPost, func(req *resty.Request) { req.SetResult(&resp).SetBody(FsGetReq{ From 483041f88a69ddede9c452b9e70a9006a50afe7b Mon Sep 17 00:00:00 2001 From: Sakura-Byte <42319937+Sakura-Byte@users.noreply.github.com> Date: Sat, 11 May 2024 23:40:59 +0800 Subject: [PATCH 5/5] 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, 13 insertions(+), 8 deletions(-) diff --git a/drivers/alist_v3/driver.go b/drivers/alist_v3/driver.go index bdcd4341e87..53fb93caa1f 100644 --- a/drivers/alist_v3/driver.go +++ b/drivers/alist_v3/driver.go @@ -109,9 +109,13 @@ 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] - userAgent := args.Header.Get("user-agent") - if userAgent == "" { - userAgent = base.UserAgent + // 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{ 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{