Skip to content

Commit

Permalink
🐛 修复AccessTokenExpired (#61#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
aoaostar committed Jul 25, 2022
1 parent 9a4f7b0 commit 21a2d00
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions pkg/alidrive/alidrive.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (drive *AliDrive) Upload(file util.FileStream) error {
}
conf.Output.Debugf("%+v,%+v", resp, e)
if e.Code != "" && e.Code != "PreHashMatched" {
if e.Code == "AccessTokenInvalid" || e.Code == "AccessTokenExpired" {
if e.Code == "AccessTokenInvalid" {
err := drive.RefreshToken()
if err != nil {
return drive.Upload(file)
Expand All @@ -125,7 +125,7 @@ func (drive *AliDrive) Upload(file util.FileStream) error {
if err != nil {
return err
}
var e = RespError{}
var e2 = RespError{}
delete(createWithFoldersBody, "pre_hash")
createWithFoldersBody["content_hash_name"] = "sha1"
createWithFoldersBody["content_hash"] = proofCode.Sha1
Expand All @@ -134,14 +134,14 @@ func (drive *AliDrive) Upload(file util.FileStream) error {
_, err = client.R().
SetBody(&createWithFoldersBody).
SetResult(&resp).
SetError(&e).
SetError(&e2).
Post(url)
conf.Output.Debugf("%+v,%+v", resp, e)
conf.Output.Debugf("%+v,%+v", resp, e2)
if err != nil {
return err
}
if e.Code != "" && e.Code != "PreHashMatched" {
return errors.New(e.Message)
if e2.Code != "" && e2.Code != "PreHashMatched" {
return errors.New(e2.Message)
}
if resp.RapidUpload {
return nil
Expand Down Expand Up @@ -186,15 +186,15 @@ func (drive *AliDrive) Upload(file util.FileStream) error {
return err
}
conf.Output.Debugf("%+v", e)
if e.Code == "AccessTokenInvalid" || e.Code == "AccessTokenExpired" {
if e.Code == "AccessTokenInvalid" {
err := drive.RefreshToken()
if err != nil {
return err
}
i--
continue
}
if e.Message == "Request has expired." {
if e.Code == "AccessDenied" {
getUploadUrlResp := GetUploadUrlResp{}
var getUploadUrlBody = util.Json{
"drive_id": drive.Instance.DriveId,
Expand All @@ -211,7 +211,7 @@ func (drive *AliDrive) Upload(file util.FileStream) error {
return err
}
conf.Output.Debugf("%+v", e2)
if e.Code == "AccessTokenInvalid" || e.Code == "AccessTokenExpired" {
if e2.Code == "AccessTokenInvalid" {
err := drive.RefreshToken()
if err != nil {
return err
Expand Down

0 comments on commit 21a2d00

Please sign in to comment.