Skip to content

Commit a3ce167

Browse files
authored
Merge pull request #58 from deadblue/develop
Bump version to 0.7.7.
2 parents 38faeab + e333aed commit a3ce167

File tree

9 files changed

+40
-36
lines changed

9 files changed

+40
-36
lines changed

internal/impl/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (c *ClientImpl) internalCall(
4141
defer c.v.ClockIn()
4242
// Prepare request
4343
if payload != nil {
44-
body, err = c.post(url, payload, context)
44+
body, err = c.Post(url, payload, nil, context)
4545
} else {
4646
body, err = c.Get(url, nil, context)
4747
}

internal/impl/body.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import "io"
55
type _BodyImpl struct {
66
rc io.ReadCloser
77

8-
size int64
9-
total int64
8+
size int64
109
}
1110

1211
func (i *_BodyImpl) Read(p []byte) (int, error) {
@@ -20,7 +19,3 @@ func (i *_BodyImpl) Close() error {
2019
func (i *_BodyImpl) Size() int64 {
2120
return i.size
2221
}
23-
24-
func (i *_BodyImpl) TotalSize() int64 {
25-
return i.total
26-
}

internal/impl/common.go

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ package impl
22

33
import (
44
"context"
5-
"io"
65
"net"
76
"net/http"
8-
"strings"
97

108
"github.com/deadblue/elevengo/internal/util"
119
"github.com/deadblue/elevengo/lowlevel/client"
@@ -47,19 +45,25 @@ func (c *ClientImpl) send(req *http.Request) (resp *http.Response, err error) {
4745
return
4846
}
4947

50-
// |post| performs an HTTP POST request to specific URL with given payload.
51-
func (c *ClientImpl) post(url string, payload client.Payload, context context.Context) (body io.ReadCloser, err error) {
48+
func (c *ClientImpl) Post(
49+
url string, payload client.Payload, headers map[string]string, context context.Context,
50+
) (body client.Body, err error) {
5251
req, err := http.NewRequestWithContext(context, http.MethodPost, url, payload)
5352
if err != nil {
5453
return
5554
}
55+
if len(headers) > 0 {
56+
for name, value := range headers {
57+
req.Header.Add(name, value)
58+
}
59+
}
5660
req.Header.Set(headerContentType, payload.ContentType())
5761
if size := payload.ContentLength(); size > 0 {
5862
req.ContentLength = size
5963
}
6064
var resp *http.Response
6165
if resp, err = c.send(req); err == nil {
62-
body = resp.Body
66+
body = makeClientBody(resp)
6367
}
6468
return
6569
}
@@ -76,22 +80,19 @@ func (c *ClientImpl) Get(
7680
req.Header.Add(name, value)
7781
}
7882
}
79-
resp, err := c.send(req)
80-
if err == nil {
81-
bi := &_BodyImpl{
82-
rc: resp.Body,
83-
size: -1,
84-
total: -1,
85-
}
86-
if hv := resp.Header.Get("Content-Length"); hv != "" {
87-
bi.size = util.ParseInt64(hv, -1)
88-
}
89-
if hv := resp.Header.Get("Content-Range"); hv != "" {
90-
if index := strings.LastIndex(hv, "/"); index >= 0 {
91-
bi.total = util.ParseInt64(hv[index+1:], -1)
92-
}
93-
}
94-
body = bi
83+
if resp, err := c.send(req); err == nil {
84+
body = makeClientBody(resp)
9585
}
9686
return
9787
}
88+
89+
func makeClientBody(resp *http.Response) client.Body {
90+
body := &_BodyImpl{
91+
rc: resp.Body,
92+
size: -1,
93+
}
94+
if hv := resp.Header.Get("Content-Length"); hv != "" {
95+
body.size = util.ParseInt64(hv, -1)
96+
}
97+
return body
98+
}

internal/protocol/cookie.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ const (
77

88
CookieNameUID = "UID"
99
CookieNameCID = "CID"
10-
CookieNameSEID = "SEID"
1110
CookieNameKID = "KID"
11+
CookieNameSEID = "SEID"
1212
)
1313

1414
var (

lowlevel/client/client.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,16 @@ type Client interface {
1313
// ExportCookies exports cookies for specific URL.
1414
ExportCookies(url string) map[string]string
1515

16-
// Get performs an HTTP GET request.
17-
Get(url string, headers map[string]string, context context.Context) (body Body, err error)
18-
1916
// CallApi calls an API.
2017
CallApi(spec ApiSpec, context context.Context) error
18+
19+
// Get performs an HTTP GET request.
20+
Get(
21+
url string, headers map[string]string, context context.Context,
22+
) (body Body, err error)
23+
24+
// Post performs an HTTP POST request.
25+
Post(
26+
url string, payload Payload, headers map[string]string, context context.Context,
27+
) (body Body, err error)
2128
}

lowlevel/client/types.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,5 @@ type (
3838

3939
// Size returns body size or -1 when unknown.
4040
Size() int64
41-
42-
// TotalSize returns total size of remote content or -1 when unknown.
43-
TotalSize() int64
4441
}
4542
)

lowlevel/errors/errors.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ var (
99

1010
ErrOfflineInvalidLink = errors.New("invalid download link")
1111

12+
ErrIPAbnormal = errors.New("ip abnormal")
1213
ErrPasswordIncorrect = errors.New("password incorrect")
1314
ErrLoginTwoStepVerify = errors.New("requires two-step verification")
1415
ErrAccountNotBindMobile = errors.New("account not binds mobile")
1516
ErrCredentialInvalid = errors.New("credential invalid")
1617
ErrSessionExited = errors.New("session exited")
1718

1819
ErrQrcodeExpired = errors.New("qrcode expired")
20+
ErrGetFailed = errors.New("get failed")
1921

2022
// ErrUnexpected is the fall-back error whose code is not handled.
2123
ErrUnexpected = errors.New("unexpected error")

lowlevel/errors/get.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ var errorsMap = map[int]error{
1919
// Common errors
2020
990002: ErrInvalidParameters,
2121
// Login errors
22+
40101004: ErrIPAbnormal,
2223
40101009: ErrPasswordIncorrect,
2324
40101010: ErrLoginTwoStepVerify,
2425
40101030: ErrAccountNotBindMobile,
2526
40101032: ErrCredentialInvalid,
2627
40101037: ErrSessionExited,
2728
// QRCode errors
2829
40199002: ErrQrcodeExpired,
30+
50199004: ErrGetFailed,
2931

3032
// Whitelist errors
3133
CodeOfflineTaskExists: nil,

version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
const (
99
libName = "elevengo"
10-
libVer = "0.7.6"
10+
libVer = "0.7.7"
1111
)
1212

1313
var (

0 commit comments

Comments
 (0)