@@ -215,6 +215,46 @@ func (d *Yun139) requestRoute(data interface{}, resp interface{}) ([]byte, error
215215 return res .Body (), nil
216216}
217217
218+ func (d * Yun139 ) ensurePersonalCloudHost () error {
219+ if d .ref != nil {
220+ return d .ref .ensurePersonalCloudHost ()
221+ }
222+ if d .PersonalCloudHost != "" {
223+ return nil
224+ }
225+ if len (d .Authorization ) == 0 {
226+ return fmt .Errorf ("authorization is empty" )
227+ }
228+ if d .Account == "" {
229+ if err := d .refreshToken (); err != nil {
230+ return err
231+ }
232+ }
233+
234+ var resp QueryRoutePolicyResp
235+ _ , err := d .requestRoute (base.Json {
236+ "userInfo" : base.Json {
237+ "userType" : 1 ,
238+ "accountType" : 1 ,
239+ "accountName" : d .Account ,
240+ },
241+ "modAddrType" : 1 ,
242+ }, & resp )
243+ if err != nil {
244+ return err
245+ }
246+ for _ , policyItem := range resp .Data .RoutePolicyList {
247+ if policyItem .ModName == "personal" && policyItem .HttpsUrl != "" {
248+ d .PersonalCloudHost = strings .TrimRight (policyItem .HttpsUrl , "/" )
249+ break
250+ }
251+ }
252+ if d .PersonalCloudHost == "" {
253+ return fmt .Errorf ("personal cloud host is empty" )
254+ }
255+ return nil
256+ }
257+
218258func (d * Yun139 ) post (pathname string , data interface {}, resp interface {}) ([]byte , error ) {
219259 return d .request (pathname , http .MethodPost , func (req * resty.Request ) {
220260 req .SetBody (data )
@@ -449,6 +489,9 @@ func unicode(str string) string {
449489}
450490
451491func (d * Yun139 ) personalRequest (pathname string , method string , callback base.ReqCallback , resp interface {}) ([]byte , error ) {
492+ if err := d .ensurePersonalCloudHost (); err != nil {
493+ return nil , err
494+ }
452495 url := d .getPersonalCloudHost () + pathname
453496 req := base .RestyClient .R ()
454497 randStr := random .String (16 )
0 commit comments