feat(cloudreve): add custom user-agent (close #5020)

This commit is contained in:
Andy Hsu 2023-08-17 19:41:21 +08:00
parent 3b74f8cd9a
commit 3bbae29f93
2 changed files with 6 additions and 2 deletions

View File

@ -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{

View File

@ -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 {