MCPcopy
hub / github.com/AlistGo/alist / request

Method request

drivers/cloudreve_v4/util.go:36–90  ·  view source on GitHub ↗
(method string, path string, callback base.ReqCallback, out any)

Source from the content-addressed store, hash-verified

34}
35
36func (d *CloudreveV4) request(method string, path string, callback base.ReqCallback, out any) error {
37 if d.ref != nil {
38 return d.ref.request(method, path, callback, out)
39 }
40 u := d.Address + "/api/v4" + path
41 req := base.RestyClient.R()
42 req.SetHeaders(map[string]string{
43 "Accept": "application/json, text/plain, */*",
44 "User-Agent": d.getUA(),
45 })
46 if d.AccessToken != "" {
47 req.SetHeader("Authorization", "Bearer "+d.AccessToken)
48 }
49
50 var r Resp
51 req.SetResult(&r)
52
53 if callback != nil {
54 callback(req)
55 }
56
57 resp, err := req.Execute(method, u)
58 if err != nil {
59 return err
60 }
61 if !resp.IsSuccess() {
62 return errors.New(resp.String())
63 }
64
65 if r.Code != 0 {
66 if r.Code == 401 && d.RefreshToken != "" && path != "/session/token/refresh" {
67 // try to refresh token
68 err = d.refreshToken()
69 if err != nil {
70 return err
71 }
72 return d.request(method, path, callback, out)
73 }
74 return errors.New(r.Msg)
75 }
76
77 if out != nil && r.Data != nil {
78 var marshal []byte
79 marshal, err = json.Marshal(r.Data)
80 if err != nil {
81 return err
82 }
83 err = json.Unmarshal(marshal, out)
84 if err != nil {
85 return err
86 }
87 }
88
89 return nil
90}
91
92func (d *CloudreveV4) login() error {
93 var siteConfig SiteLoginConfigResp

Callers 14

ListMethod · 0.95
LinkMethod · 0.95
MakeDirMethod · 0.95
MoveMethod · 0.95
RenameMethod · 0.95
CopyMethod · 0.95
RemoveMethod · 0.95
PutMethod · 0.95
loginMethod · 0.95
doLoginMethod · 0.95
refreshTokenMethod · 0.95
upLocalMethod · 0.95

Calls 6

getUAMethod · 0.95
refreshTokenMethod · 0.95
SetHeaderMethod · 0.80
IsSuccessMethod · 0.45
StringMethod · 0.45
UnmarshalMethod · 0.45

Tested by

no test coverage detected