From 4e2f24a8f053746330849ccc4b4cc5ffc7956b52 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Tue, 17 Jun 2025 18:48:55 +0800 Subject: [PATCH] fix: Fix the problem of failed Google drive backup (#9156) Refs #9129 --- .../utils/cloud_storage/client/google_drive.go | 1 - .../utils/cloud_storage/cloud_storage_client.go | 2 ++ core/constant/common.go | 2 +- core/init/migration/migrate.go | 1 + core/init/migration/migrations/init.go | 17 +++++++++++++++++ 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/agent/utils/cloud_storage/client/google_drive.go b/agent/utils/cloud_storage/client/google_drive.go index ba662f0c9..e5ad846bd 100644 --- a/agent/utils/cloud_storage/client/google_drive.go +++ b/agent/utils/cloud_storage/client/google_drive.go @@ -393,7 +393,6 @@ func RefreshGoogleToken(grantType string, tokenType string, varMap map[string]in if err := json.Unmarshal(resp.Body(), &respItem); err != nil { return "", err } - fmt.Println(respItem) if tokenType == "accessToken" { return respItem.AccessToken, nil } diff --git a/agent/utils/cloud_storage/cloud_storage_client.go b/agent/utils/cloud_storage/cloud_storage_client.go index f50b050d3..af444f851 100644 --- a/agent/utils/cloud_storage/cloud_storage_client.go +++ b/agent/utils/cloud_storage/cloud_storage_client.go @@ -41,6 +41,8 @@ func NewCloudStorageClient(backupType string, vars map[string]interface{}) (Clou return client.NewUpClient(vars) case constant.ALIYUN: return client.NewALIClient(vars) + case constant.GoogleDrive: + return client.NewGoogleDriveClient(vars) default: return nil, buserr.WithName("ErrNotSupportType", backupType) } diff --git a/core/constant/common.go b/core/constant/common.go index 70681d132..699fe8b97 100644 --- a/core/constant/common.go +++ b/core/constant/common.go @@ -32,7 +32,7 @@ const ( GoogleDrive = "GoogleDrive" OneDriveRedirectURI = "http://localhost/login/authorized" - GoogleRedirectURI = "http://localhost:8080" + GoogleRedirectURI = "https://localhost:8080" DaemonJsonPath = "/etc/docker/daemon.json" ) diff --git a/core/init/migration/migrate.go b/core/init/migration/migrate.go index dceeaf5ea..2f1187d73 100644 --- a/core/init/migration/migrate.go +++ b/core/init/migration/migrate.go @@ -17,6 +17,7 @@ func Init() { migrations.InitGoogle, migrations.AddTaskDB, migrations.AddXpackHideMenu, + migrations.UpdateGoogle, migrations.UpdateXpackHideMenu, }) if err := m.Migrate(); err != nil { diff --git a/core/init/migration/migrations/init.go b/core/init/migration/migrations/init.go index 2fcbe1c55..9f9d93dd1 100644 --- a/core/init/migration/migrations/init.go +++ b/core/init/migration/migrations/init.go @@ -440,3 +440,20 @@ var UpdateXpackHideMenu = &gormigrate.Migration{ return tx.Model(&model.Setting{}).Where("key = ?", "HideMenu").Update("value", string(updatedJSON)).Error }, } + +var UpdateGoogle = &gormigrate.Migration{ + ID: "20250616-update-google", + Migrate: func(tx *gorm.DB) error { + if err := tx.Model(&model.Setting{}). + Where("key = ?", "GoogleID"). + Update("value", "NTU2NTQ3NDYwMTQtY2Q0bGR0dDk2aGNsNWcxYWtwdmJhZTFmcjJlZ2Y0MXAuYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20=").Error; err != nil { + return err + } + if err := tx.Model(&model.Setting{}). + Where("key = ?", "GoogleSc"). + Update("value", "R09DU1BYLXRibXg0QVdVZ3d3Ykc2QW1XTHQ3YUdaZElVeE4=").Error; err != nil { + return err + } + return nil + }, +}