/
common.go
44 lines (35 loc) · 911 Bytes
/
common.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package telecom
import (
"errors"
"github.com/bookstairs/bookhunter/internal/client"
)
const (
webPrefix = "https://cloud.189.cn"
authPrefix = "https://open.e.189.cn/api/logbox/oauth2"
apiPrefix = "https://api.cloud.189.cn"
)
type Telecom struct {
*client.Client
appToken *AppLoginToken
}
func New(c *client.Config, username, password string) (*Telecom, error) {
cl, err := client.New(&client.Config{
HTTPS: false,
Host: "cloud.189.cn",
Proxy: c.Proxy,
ConfigRoot: c.ConfigRoot,
})
if err != nil {
return nil, err
}
cl.SetHeader("Accept", "application/json;charset=UTF-8")
t := &Telecom{Client: cl}
if username == "" || password == "" {
return nil, errors.New("no username or password provide, we may not able to download from telecom disk")
}
// Start to sign in.
if err := t.login(username, password); err != nil {
return nil, err
}
return t, nil
}