Skip to content

Commit

Permalink
feat(cloudreve): add custom user-agent (close #5020)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Aug 17, 2023
1 parent 3b74f8c commit 3bbae29
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions drivers/cloudreve/meta.go
Expand Up @@ -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{
Expand Down
7 changes: 5 additions & 2 deletions drivers/cloudreve/util.go
Expand Up @@ -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 {
Expand Down

0 comments on commit 3bbae29

Please sign in to comment.