From 3bbae29f9300bf537e61615d4935aa40ee74b014 Mon Sep 17 00:00:00 2001 From: Andy Hsu Date: Thu, 17 Aug 2023 19:41:21 +0800 Subject: [PATCH] feat(cloudreve): add custom user-agent (close #5020) --- drivers/cloudreve/meta.go | 1 + drivers/cloudreve/util.go | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/cloudreve/meta.go b/drivers/cloudreve/meta.go index 3c37c6d0..d01d5479 100644 --- a/drivers/cloudreve/meta.go +++ b/drivers/cloudreve/meta.go @@ -13,6 +13,7 @@ type Addition struct { Username string `json:"username"` Password string `json:"password"` Cookie string `json:"cookie"` + CustomUA string `json:"custom_ua"` } var config = driver.Config{ diff --git a/drivers/cloudreve/util.go b/drivers/cloudreve/util.go index 6a13ac7a..1b8778be 100644 --- a/drivers/cloudreve/util.go +++ b/drivers/cloudreve/util.go @@ -22,15 +22,18 @@ const loginPath = "/user/session" func (d *Cloudreve) request(method string, path string, callback base.ReqCallback, out interface{}) error { u := d.Address + "/api/v3" + path + ua := d.CustomUA + if ua == "" { + ua = base.UserAgent + } req := base.RestyClient.R() req.SetHeaders(map[string]string{ "Cookie": "cloudreve-session=" + d.Cookie, "Accept": "application/json, text/plain, */*", - "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36", + "User-Agent": ua, }) var r Resp - req.SetResult(&r) if callback != nil {