Skip to content

Commit f585133

Browse files
authored
Merge pull request #46 from deadblue/develop
Bump version to 0.6.5.
2 parents 7d0a538 + cb04edc commit f585133

File tree

15 files changed

+79
-147
lines changed

15 files changed

+79
-147
lines changed

agent.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ type Agent struct {
2020

2121
// Common parameters
2222
common types.CommonParams
23-
24-
// isWeb indicates whether the credential is for web.
25-
// Some API should use PC version when credential is not for web.
26-
isWeb bool
2723
}
2824

2925
// Default creates an Agent with default settings.
@@ -51,9 +47,9 @@ func New(options ...option.AgentOption) *Agent {
5147
}
5248
llc := impl.NewClient(hc, cdMin, cdMax)
5349
if appVer == "" {
54-
appVer, _ = getLatestAppVersion(llc)
50+
appVer, _ = getLatestAppVersion(llc, api.AppBrowserWindows)
5551
}
56-
llc.SetUserAgent(protocol.MakeUserAgent(name, appVer))
52+
llc.SetUserAgent(protocol.MakeUserAgent(name, api.AppNameBrowser, appVer))
5753
return &Agent{
5854
llc: llc,
5955
common: types.CommonParams{
@@ -62,10 +58,11 @@ func New(options ...option.AgentOption) *Agent {
6258
}
6359
}
6460

65-
func getLatestAppVersion(llc client.Client) (appVer string, err error) {
61+
func getLatestAppVersion(llc client.Client, appType string) (appVer string, err error) {
6662
spec := (&api.AppVersionSpec{}).Init()
6763
if err = llc.CallApi(spec, context.Background()); err == nil {
68-
appVer = spec.Result.LinuxApp.VersionCode
64+
versionInfo := spec.Result[appType]
65+
appVer = versionInfo.VersionCode
6966
}
7067
return
7168
}

internal/multipart/builder.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@ package multipart
33
import (
44
"bytes"
55
"fmt"
6-
"github.com/deadblue/elevengo/internal/util"
76
"io"
7+
8+
"github.com/deadblue/elevengo/internal/util"
89
)
910

1011
type FormBuilder interface {
1112
AddValue(name, value string) FormBuilder
12-
AddFile(name, filename string, r io.Reader) FormBuilder
13+
AddFile(name, filename string, filesize int64, r io.Reader) FormBuilder
1314
Build() *Form
1415
}
1516

1617
type implFormBuilder struct {
1718
// Boundary
1819
b string
19-
// Size
20+
// Total size
2021
s int64
2122
// Readers
2223
rs []io.Reader
@@ -66,7 +67,7 @@ func (b *implFormBuilder) AddValue(name string, value string) FormBuilder {
6667
return b
6768
}
6869

69-
func (b *implFormBuilder) AddFile(name string, filename string, r io.Reader) FormBuilder {
70+
func (b *implFormBuilder) AddFile(name string, filename string, filesize int64, r io.Reader) FormBuilder {
7071
// Calculate part header size
7172
size := len(b.b) + len(name) + len(filename) + 60
7273
// Write part header
@@ -79,7 +80,7 @@ func (b *implFormBuilder) AddFile(name string, filename string, r io.Reader) For
7980
buf.WriteString("\"; filename=\"")
8081
buf.WriteString(filename)
8182
buf.WriteString("\"\r\n\r\n")
82-
b.s += int64(size)
83+
b.incrSize(int64(size))
8384

8485
// Write part tail
8586
buf = &bytes.Buffer{}
@@ -89,8 +90,10 @@ func (b *implFormBuilder) AddFile(name string, filename string, r io.Reader) For
8990
b.rn += 2
9091

9192
// Update form size
92-
b.incrSize(util.GuessSize(r))
93-
b.incrSize(2)
93+
if filesize <= 0 {
94+
filesize = util.GuessSize(r)
95+
}
96+
b.incrSize(filesize + 2)
9497

9598
return b
9699
}

internal/protocol/name.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ import "fmt"
44

55
const (
66
namePrefix = "Mozilla/5.0"
7-
8-
appName = "115Desktop"
97
)
108

11-
func MakeUserAgent(name, appVer string) string {
9+
func MakeUserAgent(name, appName, appVer string) string {
1210
if name == "" {
1311
return fmt.Sprintf("%s %s/%s", namePrefix, appName, appVer)
1412
} else {

login.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ package elevengo
22

33
import (
44
"context"
5-
"strings"
65

76
"github.com/deadblue/elevengo/internal/protocol"
87
"github.com/deadblue/elevengo/lowlevel/api"
9-
"github.com/deadblue/elevengo/lowlevel/errors"
108
)
119

1210
// Credential contains required information which 115 server uses to
@@ -37,7 +35,7 @@ func (a *Agent) CredentialImport(cr *Credential) (err error) {
3735
protocol.CookieNameSEID: cr.SEID,
3836
}
3937
a.llc.ImportCookies(cookies, protocol.CookieDomains...)
40-
return a.afterSignIn(cr.UID)
38+
return a.afterSignIn()
4139
}
4240

4341
// CredentialExport exports current credentials for future-use.
@@ -48,21 +46,12 @@ func (a *Agent) CredentialExport(cr *Credential) {
4846
cr.SEID = cookies[protocol.CookieNameSEID]
4947
}
5048

51-
func (a *Agent) afterSignIn(uid string) (err error) {
49+
func (a *Agent) afterSignIn() (err error) {
5250
// Call UploadInfo API to get userId and userKey
5351
spec := (&api.UploadInfoSpec{}).Init()
54-
if err = a.llc.CallApi(spec, context.Background()); err != nil {
55-
return
56-
} else {
57-
// Save to common parameters
52+
if err = a.llc.CallApi(spec, context.Background()); err == nil {
5853
a.common.SetUserInfo(spec.Result.UserId, spec.Result.UserKey)
5954
}
60-
// Check UID
61-
parts := strings.Split(uid, "_")
62-
if len(parts) != 3 {
63-
return errors.ErrCredentialInvalid
64-
}
65-
a.isWeb = strings.HasPrefix(parts[1], "A")
6655
return
6756
}
6857

lowlevel/api/app.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,25 @@ import (
55
"github.com/deadblue/elevengo/lowlevel/types"
66
)
77

8+
const (
9+
AppAndroidLife = "Android"
10+
AppAndroidTv = "Android-tv"
11+
AppAndroidPan = "115wangpan_android"
12+
AppBrowserWindows = "PC-115chrome"
13+
AppBrowserMacOS = "MAC-115chrome"
14+
15+
AppNameBrowser = "115Browser"
16+
// Deprecated
17+
//AppNameDesktop = "115Desktop"
18+
)
19+
820
type AppVersionSpec struct {
9-
_JsonpApiSpec[types.AppVersionResult, protocol.StandardResp]
21+
_JsonApiSpec[types.AppVersionResult, protocol.StandardResp]
1022
}
1123

1224
func (s *AppVersionSpec) Init() *AppVersionSpec {
13-
s._JsonpApiSpec.Init(
14-
"https://appversion.115.com/1/web/1.0/api/chrome", "get_version",
25+
s._JsonApiSpec.Init(
26+
"https://appversion.115.com/1/web/1.0/api/getMultiVer",
1527
)
1628
return s
1729
}

lowlevel/api/json.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ func (s *_JsonApiSpec[D, R]) Parse(r io.Reader) (err error) {
7272
// Type parameters:
7373
// - D: Result type.
7474
// - R: Response type.
75+
//
76+
//lint:ignore U1000 Remain for future-use.
7577
type _JsonpApiSpec[D, R any] struct {
7678
_BasicApiSpec
7779

lowlevel/api/qrcode.go

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,15 @@ import (
88
)
99

1010
const (
11-
qrcodeTokenBaseUrl = "https://qrcodeapi.115.com/api/1.0/%s/1.0/token"
12-
qrcodeLoginBaseUrl = "https://passportapi.115.com/app/1.0/%s/1.0/login/qrcode"
13-
qrcodeImageUrl = "https://qrcodeapi.115.com/api/1.0/%s/1.0/qrcode?qrfrom=1&client=%d&uid=%s"
14-
)
15-
16-
var (
17-
qrcodeAppIds = map[string]int{
18-
"web": 0,
19-
// Client ID for app is always 7
20-
"mac": 7,
21-
"linux": 7,
22-
"windows": 7,
23-
}
11+
qrcodeImageUrl = "https://qrcodeapi.115.com/api/1.0/web/1.0/qrcode?qrfrom=1&client=0&uid=%s"
2412
)
2513

2614
type QrcodeTokenSpec struct {
2715
_JsonApiSpec[types.QrcodeTokenResult, protocol.QrcodeBaseResp]
2816
}
2917

30-
func (s *QrcodeTokenSpec) Init(appType string) *QrcodeTokenSpec {
31-
baseUrl := fmt.Sprintf(qrcodeTokenBaseUrl, appType)
32-
s._JsonApiSpec.Init(baseUrl)
18+
func (s *QrcodeTokenSpec) Init() *QrcodeTokenSpec {
19+
s._JsonApiSpec.Init("https://qrcodeapi.115.com/api/1.0/web/1.0/token")
3320
return s
3421
}
3522

@@ -50,15 +37,13 @@ type QrcodeLoginSpec struct {
5037
_JsonApiSpec[types.QrcodeLoginResult, protocol.QrcodeBaseResp]
5138
}
5239

53-
func (s *QrcodeLoginSpec) Init(appType string, uid string) *QrcodeLoginSpec {
54-
baseUrl := fmt.Sprintf(qrcodeLoginBaseUrl, appType)
55-
s._JsonApiSpec.Init(baseUrl)
40+
func (s *QrcodeLoginSpec) Init(uid string) *QrcodeLoginSpec {
41+
s._JsonApiSpec.Init("https://passportapi.115.com/app/1.0/web/1.0/login/qrcode")
5642
s.form.Set("account", uid).
57-
Set("app", appType)
43+
Set("app", "web")
5844
return s
5945
}
6046

61-
func QrcodeImageUrl(appType, userId string) string {
62-
appId := qrcodeAppIds[appType]
63-
return fmt.Sprintf(qrcodeImageUrl, appType, appId, userId)
47+
func QrcodeImageUrl(userId string) string {
48+
return fmt.Sprintf(qrcodeImageUrl, userId)
6449
}

lowlevel/api/upload.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ type UploadSampleSpec struct {
102102
}
103103

104104
func (s *UploadSampleSpec) Init(
105-
dirId, fileName string, r io.Reader,
105+
dirId, fileName string, fileSize int64, r io.Reader,
106106
initResult *types.UploadSampleInitResult,
107107
) *UploadSampleSpec {
108108
s._StandardApiSpec.Init(initResult.Host)
@@ -116,7 +116,7 @@ func (s *UploadSampleSpec) Init(
116116
AddValue("OSSAccessKeyId", initResult.AccessKeyId).
117117
AddValue("callback", initResult.Callback).
118118
AddValue("signature", initResult.Signature).
119-
AddFile("file", fileName, r).
119+
AddFile("file", fileName, fileSize, r).
120120
Build()
121121
return s
122122
}

lowlevel/api/video.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ func (s *VideoPlayWebSpec) Init(pickcode string) *VideoPlayWebSpec {
1515
return s
1616
}
1717

18-
type VideoPlayPcSpec struct {
19-
_M115ApiSpec[types.VideoPlayResult]
20-
}
18+
// type VideoPlayPcSpec struct {
19+
// _M115ApiSpec[types.VideoPlayResult]
20+
// }
2121

22-
func (s *VideoPlayPcSpec) Init(pickcode string, common *types.CommonParams) *VideoPlayPcSpec {
23-
s._M115ApiSpec.Init("https://proapi.115.com/pc/video/play")
24-
s.params.Set("format", "app").
25-
Set("appversion", common.AppVer).
26-
Set("user_id", common.UserId).
27-
Set("definition_filter", "1").
28-
Set("pickcode", pickcode)
29-
return s
30-
}
22+
// func (s *VideoPlayPcSpec) Init(pickcode string, common *types.CommonParams) *VideoPlayPcSpec {
23+
// s._M115ApiSpec.Init("https://proapi.115.com/pc/video/play")
24+
// s.params.Set("format", "app").
25+
// Set("appversion", common.AppVer).
26+
// Set("user_id", common.UserId).
27+
// Set("definition_filter", "1").
28+
// Set("pickcode", pickcode)
29+
// return s
30+
// }
3131

3232
type VideoSubtitleSpec struct {
3333
_StandardApiSpec[types.VideoSubtitleResult]

lowlevel/types/app.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
package types
22

33
type AppVersionInfo struct {
4+
AppOs int `json:"app_os"`
45
CreatedTime int64 `json:"created_time"`
56
VersionCode string `json:"version_code"`
67
VersionUrl string `json:"version_url"`
78
}
89

9-
type AppVersionResult struct {
10-
Android AppVersionInfo `json:"android"`
11-
LinuxApp AppVersionInfo `json:"linux_115"`
12-
MacBrowser AppVersionInfo `json:"mac"`
13-
MacApp AppVersionInfo `json:"mac_115"`
14-
WinBrowser AppVersionInfo `json:"win"`
15-
WinApp AppVersionInfo `json:"window_115"`
16-
}
10+
type AppVersionResult map[string]*AppVersionInfo

0 commit comments

Comments
 (0)