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

Method request

drivers/alist_v3/util.go:34–65  ·  view source on GitHub ↗
(api, method string, callback base.ReqCallback, retry ...bool)

Source from the content-addressed store, hash-verified

32}
33
34func (d *AListV3) request(api, method string, callback base.ReqCallback, retry ...bool) ([]byte, int, error) {
35 url := d.Address + "/api" + api
36 req := base.RestyClient.R()
37 req.SetHeader("Authorization", d.Token)
38 if callback != nil {
39 callback(req)
40 }
41 res, err := req.Execute(method, url)
42 if err != nil {
43 code := 0
44 if res != nil {
45 code = res.StatusCode()
46 }
47 return nil, code, err
48 }
49 log.Debugf("[alist_v3] response body: %s", res.String())
50 if res.StatusCode() >= 400 {
51 return nil, res.StatusCode(), fmt.Errorf("request failed, status: %s", res.Status())
52 }
53 code := utils.Json.Get(res.Body(), "code").ToInt()
54 if code != 200 {
55 if (code == 401 || code == 403) && !utils.IsBool(retry...) {
56 err = d.login()
57 if err != nil {
58 return nil, code, err
59 }
60 return d.request(api, method, callback, true)
61 }
62 return nil, code, fmt.Errorf("request failed,code: %d, message: %s", code, utils.Json.Get(res.Body(), "message").ToString())
63 }
64 return res.Body(), 200, nil
65}

Callers 13

InitMethod · 0.95
ListMethod · 0.95
LinkMethod · 0.95
MakeDirMethod · 0.95
MoveMethod · 0.95
RenameMethod · 0.95
CopyMethod · 0.95
RemoveMethod · 0.95
GetArchiveMetaMethod · 0.95
ListArchiveMethod · 0.95
ExtractMethod · 0.95
ArchiveDecompressMethod · 0.95

Calls 6

loginMethod · 0.95
IsBoolFunction · 0.92
SetHeaderMethod · 0.80
StatusMethod · 0.65
GetMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected