mirror of https://github.com/Xhofe/alist
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>pull/7807/head^2
parent
0d4c63e9ff
commit
cafdb4d407
|
@ -2,13 +2,11 @@ package _139
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/base64"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"path"
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/alist-org/alist/v3/drivers/base"
|
"github.com/alist-org/alist/v3/drivers/base"
|
||||||
|
@ -42,7 +40,11 @@ func (d *Yun139) Init(ctx context.Context) error {
|
||||||
if d.Authorization == "" {
|
if d.Authorization == "" {
|
||||||
return fmt.Errorf("authorization is empty")
|
return fmt.Errorf("authorization is empty")
|
||||||
}
|
}
|
||||||
d.cron = cron.NewCron(time.Hour * 24 * 7)
|
err := d.refreshToken()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
d.cron = cron.NewCron(time.Hour * 12)
|
||||||
d.cron.Do(func() {
|
d.cron.Do(func() {
|
||||||
err := d.refreshToken()
|
err := d.refreshToken()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -67,28 +69,29 @@ func (d *Yun139) Init(ctx context.Context) error {
|
||||||
default:
|
default:
|
||||||
return errs.NotImplement
|
return errs.NotImplement
|
||||||
}
|
}
|
||||||
if d.ref != nil {
|
// if d.ref != nil {
|
||||||
return nil
|
// return nil
|
||||||
}
|
// }
|
||||||
decode, err := base64.StdEncoding.DecodeString(d.Authorization)
|
// decode, err := base64.StdEncoding.DecodeString(d.Authorization)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return err
|
// return err
|
||||||
}
|
// }
|
||||||
decodeStr := string(decode)
|
// decodeStr := string(decode)
|
||||||
splits := strings.Split(decodeStr, ":")
|
// splits := strings.Split(decodeStr, ":")
|
||||||
if len(splits) < 2 {
|
// if len(splits) < 2 {
|
||||||
return fmt.Errorf("authorization is invalid, splits < 2")
|
// return fmt.Errorf("authorization is invalid, splits < 2")
|
||||||
}
|
// }
|
||||||
d.Account = splits[1]
|
// d.Account = splits[1]
|
||||||
_, err = d.post("/orchestration/personalCloud/user/v1.0/qryUserExternInfo", base.Json{
|
// _, err = d.post("/orchestration/personalCloud/user/v1.0/qryUserExternInfo", base.Json{
|
||||||
"qryUserExternInfoReq": base.Json{
|
// "qryUserExternInfoReq": base.Json{
|
||||||
"commonAccountInfo": base.Json{
|
// "commonAccountInfo": base.Json{
|
||||||
"account": d.getAccount(),
|
// "account": d.getAccount(),
|
||||||
"accountType": 1,
|
// "accountType": 1,
|
||||||
},
|
// },
|
||||||
},
|
// },
|
||||||
}, nil)
|
// }, nil)
|
||||||
return err
|
// return err
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Yun139) InitReference(storage driver.Driver) error {
|
func (d *Yun139) InitReference(storage driver.Driver) error {
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"path"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -54,17 +55,37 @@ func getTime(t string) time.Time {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Yun139) refreshToken() error {
|
func (d *Yun139) refreshToken() error {
|
||||||
if d.ref == nil {
|
if d.ref != nil {
|
||||||
return d.ref.refreshToken()
|
return d.ref.refreshToken()
|
||||||
}
|
}
|
||||||
url := "https://aas.caiyun.feixin.10086.cn:443/tellin/authTokenRefresh.do"
|
|
||||||
var resp RefreshTokenResp
|
|
||||||
decode, err := base64.StdEncoding.DecodeString(d.Authorization)
|
decode, err := base64.StdEncoding.DecodeString(d.Authorization)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("authorization decode failed: %s", err)
|
||||||
}
|
}
|
||||||
decodeStr := string(decode)
|
decodeStr := string(decode)
|
||||||
splits := strings.Split(decodeStr, ":")
|
splits := strings.Split(decodeStr, ":")
|
||||||
|
if len(splits) < 3 {
|
||||||
|
return fmt.Errorf("authorization is invalid, splits < 3")
|
||||||
|
}
|
||||||
|
strs := strings.Split(splits[2], "|")
|
||||||
|
if len(strs) < 4 {
|
||||||
|
return fmt.Errorf("authorization is invalid, strs < 4")
|
||||||
|
}
|
||||||
|
expiration, err := strconv.ParseInt(strs[3], 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("authorization is invalid")
|
||||||
|
}
|
||||||
|
expiration -= time.Now().UnixMilli()
|
||||||
|
if expiration > 1000*60*60*24*15 {
|
||||||
|
// Authorization有效期大于15天无需刷新
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if expiration < 0 {
|
||||||
|
return fmt.Errorf("authorization has expired")
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "https://aas.caiyun.feixin.10086.cn:443/tellin/authTokenRefresh.do"
|
||||||
|
var resp RefreshTokenResp
|
||||||
reqBody := "<root><token>" + splits[2] + "</token><account>" + splits[1] + "</account><clienttype>656</clienttype></root>"
|
reqBody := "<root><token>" + splits[2] + "</token><account>" + splits[1] + "</account><clienttype>656</clienttype></root>"
|
||||||
_, err = base.RestyClient.R().
|
_, err = base.RestyClient.R().
|
||||||
ForceContentType("application/xml").
|
ForceContentType("application/xml").
|
||||||
|
@ -108,15 +129,16 @@ func (d *Yun139) request(pathname string, method string, callback base.ReqCallba
|
||||||
//"mcloud-route": "001",
|
//"mcloud-route": "001",
|
||||||
"mcloud-sign": fmt.Sprintf("%s,%s,%s", ts, randStr, sign),
|
"mcloud-sign": fmt.Sprintf("%s,%s,%s", ts, randStr, sign),
|
||||||
//"mcloud-skey":"",
|
//"mcloud-skey":"",
|
||||||
"mcloud-version": "6.6.0",
|
"mcloud-version": "7.14.0",
|
||||||
"Origin": "https://yun.139.com",
|
"Origin": "https://yun.139.com",
|
||||||
"Referer": "https://yun.139.com/w/",
|
"Referer": "https://yun.139.com/w/",
|
||||||
"x-DeviceInfo": "||9|6.6.0|chrome|95.0.4638.69|uwIy75obnsRPIwlJSd7D9GhUvFwG96ce||macos 10.15.2||zh-CN|||",
|
"x-DeviceInfo": "||9|7.14.0|chrome|120.0.0.0|||windows 10||zh-CN|||",
|
||||||
"x-huawei-channelSrc": "10000034",
|
"x-huawei-channelSrc": "10000034",
|
||||||
"x-inner-ntwk": "2",
|
"x-inner-ntwk": "2",
|
||||||
"x-m4c-caller": "PC",
|
"x-m4c-caller": "PC",
|
||||||
"x-m4c-src": "10002",
|
"x-m4c-src": "10002",
|
||||||
"x-SvcType": svcType,
|
"x-SvcType": svcType,
|
||||||
|
"Inner-Hcy-Router-Https": "1",
|
||||||
})
|
})
|
||||||
|
|
||||||
var e BaseResp
|
var e BaseResp
|
||||||
|
@ -269,12 +291,12 @@ func (d *Yun139) groupGetFiles(catalogID string) ([]model.Obj, error) {
|
||||||
for {
|
for {
|
||||||
data := d.newJson(base.Json{
|
data := d.newJson(base.Json{
|
||||||
"groupID": d.CloudID,
|
"groupID": d.CloudID,
|
||||||
"catalogID": catalogID,
|
"catalogID": path.Base(catalogID),
|
||||||
"contentSortType": 0,
|
"contentSortType": 0,
|
||||||
"sortDirection": 1,
|
"sortDirection": 1,
|
||||||
"startNumber": pageNum,
|
"startNumber": pageNum,
|
||||||
"endNumber": pageNum + 99,
|
"endNumber": pageNum + 99,
|
||||||
"path": catalogID,
|
"path": path.Join(d.RootFolderID, catalogID),
|
||||||
})
|
})
|
||||||
|
|
||||||
var resp QueryGroupContentListResp
|
var resp QueryGroupContentListResp
|
||||||
|
@ -310,7 +332,7 @@ func (d *Yun139) groupGetFiles(catalogID string) ([]model.Obj, error) {
|
||||||
}
|
}
|
||||||
files = append(files, &f)
|
files = append(files, &f)
|
||||||
}
|
}
|
||||||
if pageNum > resp.Data.GetGroupContentResult.NodeCount {
|
if (pageNum + 99) > resp.Data.GetGroupContentResult.NodeCount {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
pageNum = pageNum + 100
|
pageNum = pageNum + 100
|
||||||
|
@ -393,10 +415,10 @@ func (d *Yun139) personalRequest(pathname string, method string, callback base.R
|
||||||
"Mcloud-Client": "10701",
|
"Mcloud-Client": "10701",
|
||||||
"Mcloud-Route": "001",
|
"Mcloud-Route": "001",
|
||||||
"Mcloud-Sign": fmt.Sprintf("%s,%s,%s", ts, randStr, sign),
|
"Mcloud-Sign": fmt.Sprintf("%s,%s,%s", ts, randStr, sign),
|
||||||
"Mcloud-Version": "7.13.0",
|
"Mcloud-Version": "7.14.0",
|
||||||
"Origin": "https://yun.139.com",
|
"Origin": "https://yun.139.com",
|
||||||
"Referer": "https://yun.139.com/w/",
|
"Referer": "https://yun.139.com/w/",
|
||||||
"x-DeviceInfo": "||9|7.13.0|chrome|120.0.0.0|||windows 10||zh-CN|||",
|
"x-DeviceInfo": "||9|7.14.0|chrome|120.0.0.0|||windows 10||zh-CN|||",
|
||||||
"x-huawei-channelSrc": "10000034",
|
"x-huawei-channelSrc": "10000034",
|
||||||
"x-inner-ntwk": "2",
|
"x-inner-ntwk": "2",
|
||||||
"x-m4c-caller": "PC",
|
"x-m4c-caller": "PC",
|
||||||
|
@ -405,7 +427,7 @@ func (d *Yun139) personalRequest(pathname string, method string, callback base.R
|
||||||
"X-Yun-Api-Version": "v1",
|
"X-Yun-Api-Version": "v1",
|
||||||
"X-Yun-App-Channel": "10000034",
|
"X-Yun-App-Channel": "10000034",
|
||||||
"X-Yun-Channel-Source": "10000034",
|
"X-Yun-Channel-Source": "10000034",
|
||||||
"X-Yun-Client-Info": "||9|7.13.0|chrome|120.0.0.0|||windows 10||zh-CN|||dW5kZWZpbmVk||",
|
"X-Yun-Client-Info": "||9|7.14.0|chrome|120.0.0.0|||windows 10||zh-CN|||dW5kZWZpbmVk||",
|
||||||
"X-Yun-Module-Type": "100",
|
"X-Yun-Module-Type": "100",
|
||||||
"X-Yun-Svc-Type": "1",
|
"X-Yun-Svc-Type": "1",
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue