diff --git a/drivers/aliyundrive_share/driver.go b/drivers/aliyundrive_share/driver.go index 65d5ac116fb..b0733e9bbf2 100644 --- a/drivers/aliyundrive_share/driver.go +++ b/drivers/aliyundrive_share/driver.go @@ -93,6 +93,7 @@ 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() @@ -100,14 +101,47 @@ func (d *AliyundriveShare) Link(ctx context.Context, file model.Obj, args model. 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 } diff --git a/drivers/aliyundrive_share/types.go b/drivers/aliyundrive_share/types.go index 9f16de6399b..97b6b7cf60c 100644 --- a/drivers/aliyundrive_share/types.go +++ b/drivers/aliyundrive_share/types.go @@ -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"` +}