8000 fix(139): correct path handling in groupGetFiles (#7850 closes #7848,… · AlistGo/alist@cafdb4d · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit cafdb4d

Browse files
xrgzsj2rong4cn
andauthored
fix(139): correct path handling in groupGetFiles (#7850 closes #7848,#7603)
* fix(139): correct path handling in groupGetFiles * perf(139): reduce the number of requests in groupGetFiles * refactor(139): check authorization expiration (#10) * refactor(139): check authorization expiration * fix bug * chore(139): update api version to 7.14.0 --------- Co-authored-by: j2rong4cn <36783515+j2rong4cn@users.noreply.github.com>
1 parent 0d4c63e commit cafdb4d

File tree

2 files changed

+69
-44
lines changed

2 files changed

+69
-44
lines changed

drivers/139/driver.go

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ package _139
22

33
import (
44
"context"
5-
"encoding/base64"
65
"fmt"
76
"io"
87
"net/http"
98
"path"
109
"strconv"
11-
"strings"
1210
"time"
1311

1412
"github.com/alist-org/alist/v3/drivers/base"
@@ -42,7 +40,11 @@ func (d *Yun139) Init(ctx context.Context) error {
4240
if d.Authorization == "" {
4341
return fmt.Errorf("authorization is empty")
4442
}
45-
d.cron = cron.NewCron(time.Hour * 24 * 7)
43+
err := d.refreshToken()
44+
if err != nil {
45+
return err
46+
}
47+
d.cron = cron.NewCron(time.Hour * 12)
4648
d.cron.Do(func() {
4749
err := d.refreshToken()
4850
if err != nil {
@@ -67,28 +69,29 @@ func (d *Yun139) Init(ctx context.Context) error {
6769
default:
6870
return errs.NotImplement
6971
}
70-
if d.ref != nil {
71-
return nil
72-
}
73-
decode, err := base64.StdEncoding.DecodeString(d.Authorization)
74-
if err != nil {
75-
return err
76-
}
77-
decodeStr := string(decode)
78-
splits := strings.Split(decodeStr, ":")
79-
if len(splits) < 2 {
80-
return fmt.Errorf("authorization is invalid, splits < 2")
81-
}
82-
d.Account = splits[1]
83-
_, err = d.post("/orchestration/personalCloud/user/v1.0/qryUserExternInfo", base.Json{
84-
"qryUserExternInfoReq": base.Json{
85-
"commonAccountInfo": base.Json{
86-
"account": d.getAccount(),
87-
"accountType": 1,
88-
},
89-
},
90-
}, nil)
91-
return err
72+
// if d.ref != nil {
73+
// return nil
74+
// }
75+
// decode, err := base64.StdEncoding.DecodeString(d.Authorization)
76+
// if err != nil {
77+
// return err
78+
// }
79+
// decodeStr := string(decode)
80+
// splits := strings.Split(decodeStr, ":")
81+
// if len(splits) < 2 {
82+
// return fmt.Errorf("authorization is invalid, splits < 2")
83+
// }
84+
// d.Account = splits[1]
85+
// _, err = d.post("/orchestration/personalCloud/user/v1.0/qryUserExternInfo", base.Json{
86+
// "qryUserExternInfoReq": base.Json{
87+
// "commonAccountInfo": base.Json{
88+
// "account": d.getAccount(),
89+
// "accountType": 1,
90+
// },
91+
// },
92+
// }, nil)
93+
// return err
94+
return nil
9295
}
9396

9497
func (d *Yun139) InitReference(storage driver.Driver) error {

drivers/139/util.go

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"net/http"
88
"net/url"
9+
"path"
910
"sort"
1011
"strconv"
1112
"strings"
@@ -54,17 +55,37 @@ func getTime(t string) time.Time {
5455
}
5556

5657
func (d *Yun139) refreshToken() error {
57-
if d.ref == nil {
58+
if d.ref != nil {
5859
return d.ref.refreshToken()
5960
}
60-
url := "https://aas.caiyun.feixin.10086.cn:443/tellin/authTokenRefresh.do"
61-
var resp RefreshTokenResp
6261
decode, err := base64.StdEncoding.DecodeString(d.Authorization)
6362
if err != nil {
64-
return err
63+
return fmt.Errorf("authorization decode failed: %s", err)
6564
}
6665
decodeStr := string(decode)
6766
splits := strings.Split(decodeStr, ":")
67+
if len(splits) < 3 {
68+
return fmt.Errorf("authorization is invalid, splits < 3")
69+
}
70+
strs := strings.Split(splits[2], "|")
71+
if len(strs) < 4 {
72+
return fmt.Errorf("authorization is invalid, strs < 4")
73+
}
74+
expiration, err := strconv.ParseInt(strs[3], 10, 64)
75+
if err != nil {
76+
return fmt.Errorf("authorization is invalid")
77+
}
78+
expiration -= time.Now().UnixMilli()
79+
if expiration > 1000*60*60*24*15 {
80+
// Authorization有效期大于15天无需刷新
81+
return nil
82+
}
83+
if expiration < 0 {
84+
return fmt.Errorf("authorization has expired")
85+
}
86+
87+
url := "https://aas.caiyun.feixin.10086.cn:443/tellin/authTokenRefresh.do"
88+
var resp RefreshTokenResp
6889
reqBody := "<root><token>" + splits[2] + "</token><account>" + splits[1] + "</account><clienttype>656</clienttype></root>"
6990
_, err = base.RestyClient.R().
7091
ForceContentType("application/xml").
@@ -108,15 +129,16 @@ func (d *Yun139) request(pathname string, method string, callback base.ReqCallba
108129
//"mcloud-route": "001",
109130
"mcloud-sign": fmt.Sprintf("%s,%s,%s", ts, randStr, sign),
110131
//"mcloud-skey":"",
111-
"mcloud-version": "6.6.0",
112-
"Origin": "https://yun.139.com",
113-
"Referer": "https://yun.139.com/w/",
114-
"x-DeviceInfo": "||9|6.6.0|chrome|95.0.4638.69|uwIy75obnsRPIwlJSd7D9GhUvFwG96ce||macos 10.15.2||zh-CN|||",
115-
"x-huawei-channelSrc": "10000034",
116-
"x-inner-ntwk": "2",
117-
"x-m4c-caller": "PC",
118-
"x-m4c-src": "10002",
119-
"x-SvcType": svcType,
132+
"mcloud-version": "7.14.0",
133+
"Origin": "https://yun.139.com",
134+
"Referer": "https://yun.139.com/w/",
135+
"x-DeviceInfo": "||9|7.14.0|chrome|120.0.0.0|||windows 10||zh-CN|||",
136+
"x-huawei-channelSrc": "10000034",
137+
"x-inner-ntwk": "2",
138+
"x-m4c-caller": "PC",
139+
"x-m4c-src": "10002",
140+
"x-SvcType": svcType,
141+
"Inner-Hcy-Router-Https": "1",
120142
})
121143

122144
var e BaseResp
@@ -269,12 +291,12 @@ func (d *Yun139) groupGetFiles(catalogID string) ([]model.Obj, error) {
269291
for {
270292
data := d.newJson(base.Json{
271293
"groupID": d.CloudID,
272-
"catalogID": catalogID,
294+
"catalogID": path.Base(catalogID),
273295
"contentSortType": 0,
274296
"sortDirection": 1,
275297
"startNumber": pageNum,
276298
"endNumber": pageNum + 99,
277-
"path": catalogID,
299+
"path": path.Join(d.RootFolderID, catalogID),
278300
})
279301

280302
var resp QueryGroupContentListResp
@@ -310,7 +332,7 @@ func (d *Yun139) groupGetFiles(catalogID string) ([]model.Obj, error) {
310332
}
311333
files = append(files, &f)
312334
}
313-
if pageNum > resp.Data.GetGroupContentResult.NodeCount {
335+
if (pageNum + 99) > resp.Data.GetGroupContentResult.NodeCount {
314336
break
315337
}
316338
pageNum = pageNum + 100
@@ -393,10 +415,10 @@ func (d *Yun139) personalRequest(pathname string, method string, callback base.R
393415
"Mcloud-Client": "10701",
394416
"Mcloud-Route": "001",
395417
"Mcloud-Sign": fmt.Sprintf("%s,%s,%s", ts, randStr, sign),
396-
"Mcloud-Version": "7.13.0",
418+
"Mcloud-Version": "7.14.0",
397419
"Origin": "https://yun.139.com",
398420
"Referer": "https://yun.139.com/w/",
399-
"x-DeviceInfo": "||9|7.13.0|chrome|120.0.0.0|||windows 10||zh-CN|||",
421+
"x-DeviceInfo": "||9|7.14.0|chrome|120.0.0.0|||windows 10||zh-CN|||",
400422
"x-huawei-channelSrc": "10000034",
401423
"x-inner-ntwk": "2",
402424
"x-m4c-caller": "PC",
@@ -405,7 +427,7 @@ func (d *Yun139) personalRequest(pathname string, method string, callback base.R
405427
"X-Yun-Api-Version": "v1",
406428
"X-Yun-App-Channel": "10000034",
407429
"X-Yun-Channel-Source": "10000034",
408-
"X-Yun-Client-Info": "||9|7.13.0|chrome|120.0.0.0|||windows 10||zh-CN|||dW5kZWZpbmVk||",
430+
"X-Yun-Client-Info": "||9|7.14.0|chrome|120.0.0.0|||windows 10||zh-CN|||dW5kZWZpbmVk||",
409431
"X-Yun-Module-Type": "100",
410432
"X-Yun-Svc-Type": "1",
411433
})

0 commit comments

Comments
 (0)
0