Skip to content

Commit 41bdab4

Browse files
SamPan1988panshaosenCopilotj2rong4cn
authored
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>
1 parent 8f89c55 commit 41bdab4

File tree

3 files changed

+129
-46
lines changed

3 files changed

+129
-46
lines changed

drivers/139/driver.go

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ import (
2424
type Yun139 struct {
2525
model.Storage
2626
Addition
27-
cron *cron.Cron
28-
Account string
29-
ref *Yun139
27+
cron *cron.Cron
28+
Account string
29+
ref *Yun139
30+
PersonalCloudHost string
3031
}
3132

3233
func (d *Yun139) Config() driver.Config {
@@ -39,13 +40,36 @@ func (d *Yun139) GetAddition() driver.Additional {
3940

4041
func (d *Yun139) Init(ctx context.Context) error {
4142
if d.ref == nil {
42-
if d.Authorization == "" {
43+
if len(d.Authorization) == 0 {
4344
return fmt.Errorf("authorization is empty")
4445
}
4546
err := d.refreshToken()
4647
if err != nil {
4748
return err
4849
}
50+
51+
// Query Route Policy
52+
var resp QueryRoutePolicyResp
53+
_, err = d.requestRoute(base.Json{
54+
"userInfo": base.Json{
55+
"userType": 1,
56+
"accountType": 1,
57+
"accountName": d.Account},
58+
"modAddrType": 1,
59+
}, &resp)
60+
if err != nil {
61+
return err
62+
}
63+
for _, policyItem := range resp.Data.RoutePolicyList {
64+
if policyItem.ModName == "personal" {
65+
d.PersonalCloudHost = policyItem.HttpsUrl
66+
break
67+
}
68+
}
69+
if len(d.PersonalCloudHost) == 0 {
70+
return fmt.Errorf("PersonalCloudHost is empty")
71+
}
72+
4973
d.cron = cron.NewCron(time.Hour * 12)
5074
d.cron.Do(func() {
5175
err := d.refreshToken()
@@ -71,28 +95,6 @@ func (d *Yun139) Init(ctx context.Context) error {
7195
default:
7296
return errs.NotImplement
7397
}
74-
// if d.ref != nil {
75-
// return nil
76-
// }
77-
// decode, err := base64.StdEncoding.DecodeString(d.Authorization)
78-
// if err != nil {
79-
// return err
80-
// }
81-
// decodeStr := string(decode)
82-
// splits := strings.Split(decodeStr, ":")
83-
// if len(splits) < 2 {
84-
// return fmt.Errorf("authorization is invalid, splits < 2")
85-
// }
86-
// d.Account = splits[1]
87-
// _, err = d.post("/orchestration/personalCloud/user/v1.0/qryUserExternInfo", base.Json{
88-
// "qryUserExternInfoReq": base.Json{
89-
// "commonAccountInfo": base.Json{
90-
// "account": d.getAccount(),
91-
// "accountType": 1,
92-
// },
93-
// },
94-
// }, nil)
95-
// return err
9698
return nil
9799
}
98100

@@ -160,7 +162,7 @@ func (d *Yun139) MakeDir(ctx context.Context, parentDir model.Obj, dirName strin
160162
"type": "folder",
161163
"fileRenameMode": "force_rename",
162164
}
163-
pathname := "/hcy/file/create"
165+
pathname := "/file/create"
164166
_, err = d.personalPost(pathname, data, nil)
165167
case MetaPersonal:
166168
data := base.Json{
@@ -213,7 +215,7 @@ func (d *Yun139) Move(ctx context.Context, srcObj, dstDir model.Obj) (model.Obj,
213215
"fileIds": []string{srcObj.GetID()},
214216
"toParentFileId": dstDir.GetID(),
215217
}
216-
pathname := "/hcy/file/batchMove"
218+
pathname := "/file/batchMove"
217219
_, err := d.personalPost(pathname, data, nil)
218220
if err != nil {
219221
return nil, err
@@ -290,7 +292,7 @@ func (d *Yun139) Rename(ctx context.Context, srcObj model.Obj, newName string) e
290292
"name": newName,
291293
"description": "",
292294
}
293-
pathname := "/hcy/file/update"
295+
pathname := "/file/update"
294296
_, err = d.personalPost(pathname, data, nil)
295297
case MetaPersonal:
296298
var data base.Json
@@ -390,7 +392,7 @@ func (d *Yun139) Copy(ctx context.Context, srcObj, dstDir model.Obj) error {
390392
"fileIds": []string{srcObj.GetID()},
391393
"toParentFileId": dstDir.GetID(),
392394
}
393-
pathname := "/hcy/file/batchCopy"
395+
pathname := "/file/batchCopy"
394396
_, err := d.personalPost(pathname, data, nil)
395397
return err
396398
case MetaPersonal:
@@ -430,7 +432,7 @@ func (d *Yun139) Remove(ctx context.Context, obj model.Obj) error {
430432
data := base.Json{
431433
"fileIds": []string{obj.GetID()},
432434
}
433-
pathname := "/hcy/recyclebin/batchTrash"
435+
pathname := "/recyclebin/batchTrash"
434436
_, err := d.personalPost(pathname, data, nil)
435437
return err
436438
case MetaGroup:
@@ -574,7 +576,7 @@ func (d *Yun139) Put(ctx context.Context, dstDir model.Obj, stream model.FileStr
574576
"type": "file",
575577
"fileRenameMode": "auto_rename",
576578
}
577-
pathname := "/hcy/file/create"
579+
pathname := "/file/create"
578580
var resp PersonalUploadResp
579581
_, err = d.personalPost(pathname, data, &resp)
580582
if err != nil {
@@ -611,7 +613,7 @@ func (d *Yun139) Put(ctx context.Context, dstDir model.Obj, stream model.FileStr
611613
"accountType": 1,
612614
},
613615
}
614-
pathname := "/hcy/file/getUploadUrl"
616+
pathname := "/file/getUploadUrl"
615617
var moreresp PersonalUploadUrlResp
616618
_, err = d.personalPost(pathname, moredata, &moreresp)
617619
if err != nil {
@@ -662,7 +664,7 @@ func (d *Yun139) Put(ctx context.Context, dstDir model.Obj, stream model.FileStr
662664
"fileId": resp.Data.FileId,
663665
"uploadId": resp.Data.UploadId,
664666
}
665-
_, err = d.personalPost("/hcy/file/complete", data, nil)
667+
_, err = d.personalPost("/file/complete", data, nil)
666668
if err != nil {
667669
return err
668670
}
@@ -854,7 +856,7 @@ func (d *Yun139) Other(ctx context.Context, args model.OtherArgs) (interface{},
854856
}
855857
switch args.Method {
856858
case "video_preview":
857-
uri = "/hcy/videoPreview/getPreviewInfo"
859+
uri = "/videoPreview/getPreviewInfo"
858860
default:
859861
return nil, errs.NotSupport
860862
}

drivers/139/types.go

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -285,11 +285,30 @@ type PersonalUploadUrlResp struct {
285285
}
286286
}
287287

288+
type QueryRoutePolicyResp struct {
289+
Success bool `json:"success"`
290+
Code string `json:"code"`
291+
Message string `json:"message"`
292+
Data struct {
293+
RoutePolicyList []struct {
294+
SiteID string `json:"siteID"`
295+
SiteCode string `json:"siteCode"`
296+
ModName string `json:"modName"`
297+
HttpUrl string `json:"httpUrl"`
298+
HttpsUrl string `json:"httpsUrl"`
299+
EnvID string `json:"envID"`
300+
ExtInfo string `json:"extInfo"`
301+
HashName string `json:"hashName"`
302+
ModAddrType int `json:"modAddrType"`
303+
} `json:"routePolicyList"`
304+
} `json:"data"`
305+
}
306+
288307
type RefreshTokenResp struct {
289-
XMLName xml.Name `xml:"root"`
290-
Return string `xml:"return"`
291-
Token string `xml:"token"`
292-
Expiretime int32 `xml:"expiretime"`
293-
AccessToken string `xml:"accessToken"`
294-
Desc string `xml:"desc"`
308+
XMLName xml.Name `xml:"root"`
309+
Return string `xml:"return"`
310+
Token string `xml:"token"`
311+
Expiretime int32 `xml:"expiretime"`
312+
AccessToken string `xml:"accessToken"`
313+
Desc string `xml:"desc"`
295314
}

drivers/139/util.go

Lines changed: 67 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,64 @@ func (d *Yun139) request(pathname string, method string, callback base.ReqCallba
157157
}
158158
return res.Body(), nil
159159
}
160+
161+
func (d *Yun139) requestRoute(data interface{}, resp interface{}) ([]byte, error) {
162+
url := "https://user-njs.yun.139.com/user/route/qryRoutePolicy"
163+
req := base.RestyClient.R()
164+
randStr := random.String(16)
165+
ts := time.Now().Format("2006-01-02 15:04:05")
166+
callback := func(req *resty.Request) {
167+
req.SetBody(data)
168+
}
169+
if callback != nil {
170+
callback(req)
171+
}
172+
body, err := utils.Json.Marshal(req.Body)
173+
if err != nil {
174+
return nil, err
175+
}
176+
sign := calSign(string(body), ts, randStr)
177+
svcType := "1"
178+
if d.isFamily() {
179+
svcType = "2"
180+
}
181+
req.SetHeaders(map[string]string{
182+
"Accept": "application/json, text/plain, */*",
183+
"CMS-DEVICE": "default",
184+
"Authorization": "Basic " + d.getAuthorization(),
185+
"mcloud-channel": "1000101",
186+
"mcloud-client": "10701",
187+
//"mcloud-route": "001",
188+
"mcloud-sign": fmt.Sprintf("%s,%s,%s", ts, randStr, sign),
189+
//"mcloud-skey":"",
190+
"mcloud-version": "7.14.0",
191+
"Origin": "https://yun.139.com",
192+
"Referer": "https://yun.139.com/w/",
193+
"x-DeviceInfo": "||9|7.14.0|chrome|120.0.0.0|||windows 10||zh-CN|||",
194+
"x-huawei-channelSrc": "10000034",
195+
"x-inner-ntwk": "2",
196+
"x-m4c-caller": "PC",
197+
"x-m4c-src": "10002",
198+
"x-SvcType": svcType,
199+
"Inner-Hcy-Router-Https": "1",
200+
})
201+
202+
var e BaseResp
203+
req.SetResult(&e)
204+
res, err := req.Execute(http.MethodPost, url)
205+
log.Debugln(res.String())
206+
if !e.Success {
207+
return nil, errors.New(e.Message)
208+
}
209+
if resp != nil {
210+
err = utils.Json.Unmarshal(res.Body(), resp)
211+
if err != nil {
212+
return nil, err
213+
}
214+
}
215+
return res.Body(), nil
216+
}
217+
160218
func (d *Yun139) post(pathname string, data interface{}, resp interface{}) ([]byte, error) {
161219
return d.request(pathname, http.MethodPost, func(req *resty.Request) {
162220
req.SetBody(data)
@@ -391,7 +449,7 @@ func unicode(str string) string {
391449
}
392450

393451
func (d *Yun139) personalRequest(pathname string, method string, callback base.ReqCallback, resp interface{}) ([]byte, error) {
394-
url := "https://personal-kd-njs.yun.139.com" + pathname
452+
url := d.getPersonalCloudHost() + pathname
395453
req := base.RestyClient.R()
396454
randStr := random.String(16)
397455
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
417475
"Mcloud-Route": "001",
418476
"Mcloud-Sign": fmt.Sprintf("%s,%s,%s", ts, randStr, sign),
419477
"Mcloud-Version": "7.14.0",
420-
"Origin": "https://yun.139.com",
421-
"Referer": "https://yun.139.com/w/",
422478
"x-DeviceInfo": "||9|7.14.0|chrome|120.0.0.0|||windows 10||zh-CN|||",
423479
"x-huawei-channelSrc": "10000034",
424480
"x-inner-ntwk": "2",
@@ -480,7 +536,7 @@ func (d *Yun139) personalGetFiles(fileId string) ([]model.Obj, error) {
480536
"parentFileId": fileId,
481537
}
482538
var resp PersonalListResp
483-
_, err := d.personalPost("/hcy/file/list", data, &resp)
539+
_, err := d.personalPost("/file/list", data, &resp)
484540
if err != nil {
485541
return nil, err
486542
}
@@ -528,7 +584,7 @@ func (d *Yun139) personalGetLink(fileId string) (string, error) {
528584
data := base.Json{
529585
"fileId": fileId,
530586
}
531-
res, err := d.personalPost("/hcy/file/getDownloadUrl",
587+
res, err := d.personalPost("/file/getDownloadUrl",
532588
data, nil)
533589
if err != nil {
534590
return "", err
@@ -553,3 +609,9 @@ func (d *Yun139) getAccount() string {
553609
}
554610
return d.Account
555611
}
612+
func (d *Yun139) getPersonalCloudHost() string {
613+
if d.ref != nil {
614+
return d.ref.getPersonalCloudHost()
615+
}
616+
return d.PersonalCloudHost
617+
}

0 commit comments

Comments
 (0)