Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alist-org
GitHub Repository: alist-org/alist
Path: blob/main/drivers/lenovonas_share/util.go
1986 views
1
package LenovoNasShare
2
3
import (
4
"errors"
5
6
"github.com/alist-org/alist/v3/drivers/base"
7
"github.com/alist-org/alist/v3/pkg/utils"
8
jsoniter "github.com/json-iterator/go"
9
)
10
11
func (d *LenovoNasShare) request(url string, method string, callback base.ReqCallback, resp interface{}) ([]byte, error) {
12
req := base.RestyClient.R()
13
req.SetHeaders(map[string]string{
14
"origin": "https://siot-share.lenovo.com.cn",
15
"referer": "https://siot-share.lenovo.com.cn/",
16
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) alist-client",
17
"platform": "web",
18
"app-version": "3",
19
})
20
if callback != nil {
21
callback(req)
22
}
23
if resp != nil {
24
req.SetResult(resp)
25
}
26
res, err := req.Execute(method, url)
27
if err != nil {
28
return nil, err
29
}
30
body := res.Body()
31
result := utils.Json.Get(body, "result").ToBool()
32
if !result {
33
return nil, errors.New(jsoniter.Get(body, "error", "msg").ToString())
34
}
35
return body, nil
36
}
37
38