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 (
 | 
			
		||||
	"context"
 | 
			
		||||
	"encoding/base64"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"io"
 | 
			
		||||
	"net/http"
 | 
			
		||||
	"path"
 | 
			
		||||
	"strconv"
 | 
			
		||||
	"strings"
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	"github.com/alist-org/alist/v3/drivers/base"
 | 
			
		||||
| 
						 | 
				
			
			@ -42,7 +40,11 @@ func (d *Yun139) Init(ctx context.Context) error {
 | 
			
		|||
		if d.Authorization == "" {
 | 
			
		||||
			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() {
 | 
			
		||||
			err := d.refreshToken()
 | 
			
		||||
			if err != nil {
 | 
			
		||||
| 
						 | 
				
			
			@ -67,28 +69,29 @@ func (d *Yun139) Init(ctx context.Context) error {
 | 
			
		|||
	default:
 | 
			
		||||
		return errs.NotImplement
 | 
			
		||||
	}
 | 
			
		||||
	if d.ref != nil {
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
	decode, err := base64.StdEncoding.DecodeString(d.Authorization)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	decodeStr := string(decode)
 | 
			
		||||
	splits := strings.Split(decodeStr, ":")
 | 
			
		||||
	if len(splits) < 2 {
 | 
			
		||||
		return fmt.Errorf("authorization is invalid, splits < 2")
 | 
			
		||||
	}
 | 
			
		||||
	d.Account = splits[1]
 | 
			
		||||
	_, err = d.post("/orchestration/personalCloud/user/v1.0/qryUserExternInfo", base.Json{
 | 
			
		||||
		"qryUserExternInfoReq": base.Json{
 | 
			
		||||
			"commonAccountInfo": base.Json{
 | 
			
		||||
				"account":     d.getAccount(),
 | 
			
		||||
				"accountType": 1,
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
	}, nil)
 | 
			
		||||
	return err
 | 
			
		||||
	// if d.ref != nil {
 | 
			
		||||
	// 	return nil
 | 
			
		||||
	// }
 | 
			
		||||
	// decode, err := base64.StdEncoding.DecodeString(d.Authorization)
 | 
			
		||||
	// if err != nil {
 | 
			
		||||
	// 	return err
 | 
			
		||||
	// }
 | 
			
		||||
	// decodeStr := string(decode)
 | 
			
		||||
	// splits := strings.Split(decodeStr, ":")
 | 
			
		||||
	// if len(splits) < 2 {
 | 
			
		||||
	// 	return fmt.Errorf("authorization is invalid, splits < 2")
 | 
			
		||||
	// }
 | 
			
		||||
	// d.Account = splits[1]
 | 
			
		||||
	// _, err = d.post("/orchestration/personalCloud/user/v1.0/qryUserExternInfo", base.Json{
 | 
			
		||||
	// 	"qryUserExternInfoReq": base.Json{
 | 
			
		||||
	// 		"commonAccountInfo": base.Json{
 | 
			
		||||
	// 			"account":     d.getAccount(),
 | 
			
		||||
	// 			"accountType": 1,
 | 
			
		||||
	// 		},
 | 
			
		||||
	// 	},
 | 
			
		||||
	// }, nil)
 | 
			
		||||
	// return err
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (d *Yun139) InitReference(storage driver.Driver) error {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,6 +6,7 @@ import (
 | 
			
		|||
	"fmt"
 | 
			
		||||
	"net/http"
 | 
			
		||||
	"net/url"
 | 
			
		||||
	"path"
 | 
			
		||||
	"sort"
 | 
			
		||||
	"strconv"
 | 
			
		||||
	"strings"
 | 
			
		||||
| 
						 | 
				
			
			@ -54,17 +55,37 @@ func getTime(t string) time.Time {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
func (d *Yun139) refreshToken() error {
 | 
			
		||||
	if d.ref == nil {
 | 
			
		||||
	if d.ref != nil {
 | 
			
		||||
		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)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
		return fmt.Errorf("authorization decode failed: %s", err)
 | 
			
		||||
	}
 | 
			
		||||
	decodeStr := string(decode)
 | 
			
		||||
	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>"
 | 
			
		||||
	_, err = base.RestyClient.R().
 | 
			
		||||
		ForceContentType("application/xml").
 | 
			
		||||
| 
						 | 
				
			
			@ -108,15 +129,16 @@ func (d *Yun139) request(pathname string, method string, callback base.ReqCallba
 | 
			
		|||
		//"mcloud-route": "001",
 | 
			
		||||
		"mcloud-sign": fmt.Sprintf("%s,%s,%s", ts, randStr, sign),
 | 
			
		||||
		//"mcloud-skey":"",
 | 
			
		||||
		"mcloud-version":      "6.6.0",
 | 
			
		||||
		"Origin":              "https://yun.139.com",
 | 
			
		||||
		"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-huawei-channelSrc": "10000034",
 | 
			
		||||
		"x-inner-ntwk":        "2",
 | 
			
		||||
		"x-m4c-caller":        "PC",
 | 
			
		||||
		"x-m4c-src":           "10002",
 | 
			
		||||
		"x-SvcType":           svcType,
 | 
			
		||||
		"mcloud-version":         "7.14.0",
 | 
			
		||||
		"Origin":                 "https://yun.139.com",
 | 
			
		||||
		"Referer":                "https://yun.139.com/w/",
 | 
			
		||||
		"x-DeviceInfo":           "||9|7.14.0|chrome|120.0.0.0|||windows 10||zh-CN|||",
 | 
			
		||||
		"x-huawei-channelSrc":    "10000034",
 | 
			
		||||
		"x-inner-ntwk":           "2",
 | 
			
		||||
		"x-m4c-caller":           "PC",
 | 
			
		||||
		"x-m4c-src":              "10002",
 | 
			
		||||
		"x-SvcType":              svcType,
 | 
			
		||||
		"Inner-Hcy-Router-Https": "1",
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
	var e BaseResp
 | 
			
		||||
| 
						 | 
				
			
			@ -269,12 +291,12 @@ func (d *Yun139) groupGetFiles(catalogID string) ([]model.Obj, error) {
 | 
			
		|||
	for {
 | 
			
		||||
		data := d.newJson(base.Json{
 | 
			
		||||
			"groupID":         d.CloudID,
 | 
			
		||||
			"catalogID":       catalogID,
 | 
			
		||||
			"catalogID":       path.Base(catalogID),
 | 
			
		||||
			"contentSortType": 0,
 | 
			
		||||
			"sortDirection":   1,
 | 
			
		||||
			"startNumber":     pageNum,
 | 
			
		||||
			"endNumber":       pageNum + 99,
 | 
			
		||||
			"path":            catalogID,
 | 
			
		||||
			"path":            path.Join(d.RootFolderID, catalogID),
 | 
			
		||||
		})
 | 
			
		||||
 | 
			
		||||
		var resp QueryGroupContentListResp
 | 
			
		||||
| 
						 | 
				
			
			@ -310,7 +332,7 @@ func (d *Yun139) groupGetFiles(catalogID string) ([]model.Obj, error) {
 | 
			
		|||
			}
 | 
			
		||||
			files = append(files, &f)
 | 
			
		||||
		}
 | 
			
		||||
		if pageNum > resp.Data.GetGroupContentResult.NodeCount {
 | 
			
		||||
		if (pageNum + 99) > resp.Data.GetGroupContentResult.NodeCount {
 | 
			
		||||
			break
 | 
			
		||||
		}
 | 
			
		||||
		pageNum = pageNum + 100
 | 
			
		||||
| 
						 | 
				
			
			@ -393,10 +415,10 @@ func (d *Yun139) personalRequest(pathname string, method string, callback base.R
 | 
			
		|||
		"Mcloud-Client":        "10701",
 | 
			
		||||
		"Mcloud-Route":         "001",
 | 
			
		||||
		"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",
 | 
			
		||||
		"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-inner-ntwk":         "2",
 | 
			
		||||
		"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-App-Channel":    "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-Svc-Type":       "1",
 | 
			
		||||
	})
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue