@@ -24,9 +24,10 @@ import (
2424type 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
3233func (d * Yun139 ) Config () driver.Config {
@@ -39,13 +40,36 @@ func (d *Yun139) GetAddition() driver.Additional {
3940
4041func (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 }
0 commit comments