Skip to content

Commit

Permalink
fix: use get_share_link_download_url if can't get_download_url (c…
Browse files Browse the repository at this point in the history
…lose #1753)
  • Loading branch information
xhofe committed Sep 25, 2022
1 parent 96d8a38 commit 5ac6a30
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
38 changes: 36 additions & 2 deletions drivers/aliyundrive_share/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,55 @@ func (d *AliyundriveShare) Link(ctx context.Context, file model.Obj, args model.
if err != nil {
return nil, err
}
var u string
if e.Code != "" {
if e.Code == "AccessTokenInvalid" {
err = d.refreshToken()
if err != nil {
return nil, err
}
return d.Link(ctx, file, args)
} else if e.Code == "ForbiddenNoPermission.File" {
data = utils.MergeMap(data, base.Json{
// Only ten minutes valid
"expire_sec": 600,
"share_id": d.ShareId,
})
var resp ShareLinkResp
var e2 ErrorResp
_, err = base.RestyClient.R().
SetError(&e2).SetBody(data).SetResult(&resp).
SetHeader("content-type", "application/json").
SetHeader("Authorization", "Bearer\t"+d.AccessToken).
SetHeader("x-share-token", d.ShareToken).
Post("https://api.aliyundrive.com/v2/file/get_share_link_download_url")
if err != nil {
return nil, err
}
if e2.Code != "" {
if e2.Code == "AccessTokenInvalid" || e2.Code == "ShareLinkTokenInvalid" {
err = d.getShareToken()
if err != nil {
return nil, err
}
return d.Link(ctx, file, args)
} else {
return nil, errors.New(e2.Code + ":" + e2.Message)
}
} else {
u = resp.DownloadUrl
}
} else {
return nil, errors.New(e.Code + ":" + e.Message)
}
return nil, errors.New(e.Message)
} else {
u = utils.Json.Get(res.Body(), "url").ToString()
}
return &model.Link{
Header: http.Header{
"Referer": []string{"https://www.aliyundrive.com/"},
},
URL: utils.Json.Get(res.Body(), "url").ToString(),
URL: u,
}, nil
}

Expand Down
10 changes: 5 additions & 5 deletions drivers/aliyundrive_share/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ func fileToObj(f File) *model.ObjThumb {
}
}

//type ShareLinkResp struct {
// DownloadUrl string `json:"download_url"`
// Url string `json:"url"`
// Thumbnail string `json:"thumbnail"`
//}
type ShareLinkResp struct {
DownloadUrl string `json:"download_url"`
Url string `json:"url"`
Thumbnail string `json:"thumbnail"`
}

0 comments on commit 5ac6a30

Please sign in to comment.