fix(139): incorrect host (#8368)
* fix: correct new personal cloud path for 139Driver * Update drivers/139/driver.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix bug --------- Co-authored-by: panshaosen <19802021493@139.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: j2rong4cn <253551464@qq.com>
This commit is contained in:
parent
8f89c55aca
commit
41bdab49aa
@ -24,9 +24,10 @@ import (
|
|||||||
type Yun139 struct {
|
type Yun139 struct {
|
||||||
model.Storage
|
model.Storage
|
||||||
Addition
|
Addition
|
||||||
cron *cron.Cron
|
cron *cron.Cron
|
||||||
Account string
|
Account string
|
||||||
ref *Yun139
|
ref *Yun139
|
||||||
|
PersonalCloudHost string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Yun139) Config() driver.Config {
|
func (d *Yun139) Config() driver.Config {
|
||||||
@ -39,13 +40,36 @@ func (d *Yun139) GetAddition() driver.Additional {
|
|||||||
|
|
||||||
func (d *Yun139) Init(ctx context.Context) error {
|
func (d *Yun139) Init(ctx context.Context) error {
|
||||||
if d.ref == nil {
|
if d.ref == nil {
|
||||||
if d.Authorization == "" {
|
if len(d.Authorization) == 0 {
|
||||||
return fmt.Errorf("authorization is empty")
|
return fmt.Errorf("authorization is empty")
|
||||||
}
|
}
|
||||||
err := d.refreshToken()
|
err := d.refreshToken()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Query Route Policy
|
||||||
|
var resp QueryRoutePolicyResp
|
||||||
|
_, err = d.requestRoute(base.Json{
|
||||||
|
"userInfo": base.Json{
|
||||||
|
"userType": 1,
|
||||||
|
"accountType": 1,
|
||||||
|
"accountName": d.Account},
|
||||||
|
"modAddrType": 1,
|
||||||
|
}, &resp)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, policyItem := range resp.Data.RoutePolicyList {
|
||||||
|
if policyItem.ModName == "personal" {
|
||||||
|
d.PersonalCloudHost = policyItem.HttpsUrl
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(d.PersonalCloudHost) == 0 {
|
||||||
|
return fmt.Errorf("PersonalCloudHost is empty")
|
||||||
|
}
|
||||||
|
|
||||||
d.cron = cron.NewCron(time.Hour * 12)
|
d.cron = cron.NewCron(time.Hour * 12)
|
||||||
d.cron.Do(func() {
|
d.cron.Do(func() {
|
||||||
err := d.refreshToken()
|
err := d.refreshToken()
|
||||||
@ -71,28 +95,6 @@ func (d *Yun139) Init(ctx context.Context) error {
|
|||||||
default:
|
default:
|
||||||
return errs.NotImplement
|
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
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,7 +162,7 @@ func (d *Yun139) MakeDir(ctx context.Context, parentDir model.Obj, dirName strin
|
|||||||
"type": "folder",
|
"type": "folder",
|
||||||
"fileRenameMode": "force_rename",
|
"fileRenameMode": "force_rename",
|
||||||
}
|
}
|
||||||
pathname := "/hcy/file/create"
|
pathname := "/file/create"
|
||||||
_, err = d.personalPost(pathname, data, nil)
|
_, err = d.personalPost(pathname, data, nil)
|
||||||
case MetaPersonal:
|
case MetaPersonal:
|
||||||
data := base.Json{
|
data := base.Json{
|
||||||
@ -213,7 +215,7 @@ func (d *Yun139) Move(ctx context.Context, srcObj, dstDir model.Obj) (model.Obj,
|
|||||||
"fileIds": []string{srcObj.GetID()},
|
"fileIds": []string{srcObj.GetID()},
|
||||||
"toParentFileId": dstDir.GetID(),
|
"toParentFileId": dstDir.GetID(),
|
||||||
}
|
}
|
||||||
pathname := "/hcy/file/batchMove"
|
pathname := "/file/batchMove"
|
||||||
_, err := d.personalPost(pathname, data, nil)
|
_, err := d.personalPost(pathname, data, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -290,7 +292,7 @@ func (d *Yun139) Rename(ctx context.Context, srcObj model.Obj, newName string) e
|
|||||||
"name": newName,
|
"name": newName,
|
||||||
"description": "",
|
"description": "",
|
||||||
}
|
}
|
||||||
pathname := "/hcy/file/update"
|
pathname := "/file/update"
|
||||||
_, err = d.personalPost(pathname, data, nil)
|
_, err = d.personalPost(pathname, data, nil)
|
||||||
case MetaPersonal:
|
case MetaPersonal:
|
||||||
var data base.Json
|
var data base.Json
|
||||||
@ -390,7 +392,7 @@ func (d *Yun139) Copy(ctx context.Context, srcObj, dstDir model.Obj) error {
|
|||||||
"fileIds": []string{srcObj.GetID()},
|
"fileIds": []string{srcObj.GetID()},
|
||||||
"toParentFileId": dstDir.GetID(),
|
"toParentFileId": dstDir.GetID(),
|
||||||
}
|
}
|
||||||
pathname := "/hcy/file/batchCopy"
|
pathname := "/file/batchCopy"
|
||||||
_, err := d.personalPost(pathname, data, nil)
|
_, err := d.personalPost(pathname, data, nil)
|
||||||
return err
|
return err
|
||||||
case MetaPersonal:
|
case MetaPersonal:
|
||||||
@ -430,7 +432,7 @@ func (d *Yun139) Remove(ctx context.Context, obj model.Obj) error {
|
|||||||
data := base.Json{
|
data := base.Json{
|
||||||
"fileIds": []string{obj.GetID()},
|
"fileIds": []string{obj.GetID()},
|
||||||
}
|
}
|
||||||
pathname := "/hcy/recyclebin/batchTrash"
|
pathname := "/recyclebin/batchTrash"
|
||||||
_, err := d.personalPost(pathname, data, nil)
|
_, err := d.personalPost(pathname, data, nil)
|
||||||
return err
|
return err
|
||||||
case MetaGroup:
|
case MetaGroup:
|
||||||
@ -574,7 +576,7 @@ func (d *Yun139) Put(ctx context.Context, dstDir model.Obj, stream model.FileStr
|
|||||||
"type": "file",
|
"type": "file",
|
||||||
"fileRenameMode": "auto_rename",
|
"fileRenameMode": "auto_rename",
|
||||||
}
|
}
|
||||||
pathname := "/hcy/file/create"
|
pathname := "/file/create"
|
||||||
var resp PersonalUploadResp
|
var resp PersonalUploadResp
|
||||||
_, err = d.personalPost(pathname, data, &resp)
|
_, err = d.personalPost(pathname, data, &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -611,7 +613,7 @@ func (d *Yun139) Put(ctx context.Context, dstDir model.Obj, stream model.FileStr
|
|||||||
"accountType": 1,
|
"accountType": 1,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
pathname := "/hcy/file/getUploadUrl"
|
pathname := "/file/getUploadUrl"
|
||||||
var moreresp PersonalUploadUrlResp
|
var moreresp PersonalUploadUrlResp
|
||||||
_, err = d.personalPost(pathname, moredata, &moreresp)
|
_, err = d.personalPost(pathname, moredata, &moreresp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -662,7 +664,7 @@ func (d *Yun139) Put(ctx context.Context, dstDir model.Obj, stream model.FileStr
|
|||||||
"fileId": resp.Data.FileId,
|
"fileId": resp.Data.FileId,
|
||||||
"uploadId": resp.Data.UploadId,
|
"uploadId": resp.Data.UploadId,
|
||||||
}
|
}
|
||||||
_, err = d.personalPost("/hcy/file/complete", data, nil)
|
_, err = d.personalPost("/file/complete", data, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -854,7 +856,7 @@ func (d *Yun139) Other(ctx context.Context, args model.OtherArgs) (interface{},
|
|||||||
}
|
}
|
||||||
switch args.Method {
|
switch args.Method {
|
||||||
case "video_preview":
|
case "video_preview":
|
||||||
uri = "/hcy/videoPreview/getPreviewInfo"
|
uri = "/videoPreview/getPreviewInfo"
|
||||||
default:
|
default:
|
||||||
return nil, errs.NotSupport
|
return nil, errs.NotSupport
|
||||||
}
|
}
|
||||||
|
@ -285,11 +285,30 @@ type PersonalUploadUrlResp struct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type RefreshTokenResp struct {
|
type QueryRoutePolicyResp struct {
|
||||||
XMLName xml.Name `xml:"root"`
|
Success bool `json:"success"`
|
||||||
Return string `xml:"return"`
|
Code string `json:"code"`
|
||||||
Token string `xml:"token"`
|
Message string `json:"message"`
|
||||||
Expiretime int32 `xml:"expiretime"`
|
Data struct {
|
||||||
AccessToken string `xml:"accessToken"`
|
RoutePolicyList []struct {
|
||||||
Desc string `xml:"desc"`
|
SiteID string `json:"siteID"`
|
||||||
|
SiteCode string `json:"siteCode"`
|
||||||
|
ModName string `json:"modName"`
|
||||||
|
HttpUrl string `json:"httpUrl"`
|
||||||
|
HttpsUrl string `json:"httpsUrl"`
|
||||||
|
EnvID string `json:"envID"`
|
||||||
|
ExtInfo string `json:"extInfo"`
|
||||||
|
HashName string `json:"hashName"`
|
||||||
|
ModAddrType int `json:"modAddrType"`
|
||||||
|
} `json:"routePolicyList"`
|
||||||
|
} `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type RefreshTokenResp struct {
|
||||||
|
XMLName xml.Name `xml:"root"`
|
||||||
|
Return string `xml:"return"`
|
||||||
|
Token string `xml:"token"`
|
||||||
|
Expiretime int32 `xml:"expiretime"`
|
||||||
|
AccessToken string `xml:"accessToken"`
|
||||||
|
Desc string `xml:"desc"`
|
||||||
}
|
}
|
||||||
|
@ -157,6 +157,64 @@ func (d *Yun139) request(pathname string, method string, callback base.ReqCallba
|
|||||||
}
|
}
|
||||||
return res.Body(), nil
|
return res.Body(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *Yun139) requestRoute(data interface{}, resp interface{}) ([]byte, error) {
|
||||||
|
url := "https://user-njs.yun.139.com/user/route/qryRoutePolicy"
|
||||||
|
req := base.RestyClient.R()
|
||||||
|
randStr := random.String(16)
|
||||||
|
ts := time.Now().Format("2006-01-02 15:04:05")
|
||||||
|
callback := func(req *resty.Request) {
|
||||||
|
req.SetBody(data)
|
||||||
|
}
|
||||||
|
if callback != nil {
|
||||||
|
callback(req)
|
||||||
|
}
|
||||||
|
body, err := utils.Json.Marshal(req.Body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
sign := calSign(string(body), ts, randStr)
|
||||||
|
svcType := "1"
|
||||||
|
if d.isFamily() {
|
||||||
|
svcType = "2"
|
||||||
|
}
|
||||||
|
req.SetHeaders(map[string]string{
|
||||||
|
"Accept": "application/json, text/plain, */*",
|
||||||
|
"CMS-DEVICE": "default",
|
||||||
|
"Authorization": "Basic " + d.getAuthorization(),
|
||||||
|
"mcloud-channel": "1000101",
|
||||||
|
"mcloud-client": "10701",
|
||||||
|
//"mcloud-route": "001",
|
||||||
|
"mcloud-sign": fmt.Sprintf("%s,%s,%s", ts, randStr, sign),
|
||||||
|
//"mcloud-skey":"",
|
||||||
|
"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
|
||||||
|
req.SetResult(&e)
|
||||||
|
res, err := req.Execute(http.MethodPost, url)
|
||||||
|
log.Debugln(res.String())
|
||||||
|
if !e.Success {
|
||||||
|
return nil, errors.New(e.Message)
|
||||||
|
}
|
||||||
|
if resp != nil {
|
||||||
|
err = utils.Json.Unmarshal(res.Body(), resp)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res.Body(), nil
|
||||||
|
}
|
||||||
|
|
||||||
func (d *Yun139) post(pathname string, data interface{}, resp interface{}) ([]byte, error) {
|
func (d *Yun139) post(pathname string, data interface{}, resp interface{}) ([]byte, error) {
|
||||||
return d.request(pathname, http.MethodPost, func(req *resty.Request) {
|
return d.request(pathname, http.MethodPost, func(req *resty.Request) {
|
||||||
req.SetBody(data)
|
req.SetBody(data)
|
||||||
@ -391,7 +449,7 @@ func unicode(str string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *Yun139) personalRequest(pathname string, method string, callback base.ReqCallback, resp interface{}) ([]byte, error) {
|
func (d *Yun139) personalRequest(pathname string, method string, callback base.ReqCallback, resp interface{}) ([]byte, error) {
|
||||||
url := "https://personal-kd-njs.yun.139.com" + pathname
|
url := d.getPersonalCloudHost() + pathname
|
||||||
req := base.RestyClient.R()
|
req := base.RestyClient.R()
|
||||||
randStr := random.String(16)
|
randStr := random.String(16)
|
||||||
ts := time.Now().Format("2006-01-02 15:04:05")
|
ts := time.Now().Format("2006-01-02 15:04:05")
|
||||||
@ -417,8 +475,6 @@ func (d *Yun139) personalRequest(pathname string, method string, callback base.R
|
|||||||
"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.14.0",
|
"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-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",
|
||||||
@ -480,7 +536,7 @@ func (d *Yun139) personalGetFiles(fileId string) ([]model.Obj, error) {
|
|||||||
"parentFileId": fileId,
|
"parentFileId": fileId,
|
||||||
}
|
}
|
||||||
var resp PersonalListResp
|
var resp PersonalListResp
|
||||||
_, err := d.personalPost("/hcy/file/list", data, &resp)
|
_, err := d.personalPost("/file/list", data, &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -528,7 +584,7 @@ func (d *Yun139) personalGetLink(fileId string) (string, error) {
|
|||||||
data := base.Json{
|
data := base.Json{
|
||||||
"fileId": fileId,
|
"fileId": fileId,
|
||||||
}
|
}
|
||||||
res, err := d.personalPost("/hcy/file/getDownloadUrl",
|
res, err := d.personalPost("/file/getDownloadUrl",
|
||||||
data, nil)
|
data, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@ -553,3 +609,9 @@ func (d *Yun139) getAccount() string {
|
|||||||
}
|
}
|
||||||
return d.Account
|
return d.Account
|
||||||
}
|
}
|
||||||
|
func (d *Yun139) getPersonalCloudHost() string {
|
||||||
|
if d.ref != nil {
|
||||||
|
return d.ref.getPersonalCloudHost()
|
||||||
|
}
|
||||||
|
return d.PersonalCloudHost
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user