From 23fe54ce0b24e2fd74848bdfdd3b6b384dd2bab8 Mon Sep 17 00:00:00 2001 From: tickstep Date: Sun, 2 Apr 2023 09:37:42 +0800 Subject: [PATCH] refactor create session --- internal/command/utils.go | 5 +---- internal/config/pan_user.go | 10 +++++----- internal/syncdrive/file_action_task_mgr_test.go | 11 ++++++++++- internal/syncdrive/sync_db_test.go | 11 ++++++++++- internal/syncdrive/sync_task_mgr_test.go | 15 ++++++++++++--- internal/syncdrive/sync_task_test.go | 11 ++++++++++- 6 files changed, 48 insertions(+), 15 deletions(-) diff --git a/internal/command/utils.go b/internal/command/utils.go index 54801bc..a658382 100644 --- a/internal/command/utils.go +++ b/internal/command/utils.go @@ -169,10 +169,7 @@ func RefreshTokenInNeed(activeUser *config.PanUser, deviceName string) bool { } // create new signature - _, e := activeUser.PanClient().CreateSession(&aliyunpan.CreateSessionParam{ - DeviceName: deviceName, - ModelName: "Windows网页版", - }) + _, e := activeUser.PanClient().CreateSession(nil) if e != nil { logger.Verboseln("call CreateSession error in RefreshTokenInNeed: " + e.Error()) } diff --git a/internal/config/pan_user.go b/internal/config/pan_user.go index 182fbab..33f7e0d 100644 --- a/internal/config/pan_user.go +++ b/internal/config/pan_user.go @@ -87,7 +87,10 @@ doLoginAct: Nonce: 0, PublicKey: "", } - panClient := aliyunpan.NewPanClient(*webToken, aliyunpan.AppLoginToken{}, appConfig) + panClient := aliyunpan.NewPanClient(*webToken, aliyunpan.AppLoginToken{}, appConfig, aliyunpan.SessionConfig{ + DeviceName: deviceName, + ModelName: "Windows网页版", + }) u := &PanUser{ WebToken: *webToken, panClient: panClient, @@ -137,10 +140,7 @@ doLoginAct: // create session appConfig.UserId = u.UserId panClient.UpdateAppConfig(appConfig) - r, e := panClient.CreateSession(&aliyunpan.CreateSessionParam{ - DeviceName: deviceName, - ModelName: "Windows网页版", - }) + r, e := panClient.CreateSession(nil) if e != nil { logger.Verboseln("call CreateSession error in SetupUserByCookie: " + e.Error()) } diff --git a/internal/syncdrive/file_action_task_mgr_test.go b/internal/syncdrive/file_action_task_mgr_test.go index 902a7db..ac6cc17 100644 --- a/internal/syncdrive/file_action_task_mgr_test.go +++ b/internal/syncdrive/file_action_task_mgr_test.go @@ -19,7 +19,16 @@ func TestFileActionMgrStart(t *testing.T) { } // pan client - panClient := aliyunpan.NewPanClient(*webToken, aliyunpan.AppLoginToken{}) + panClient := aliyunpan.NewPanClient(*webToken, aliyunpan.AppLoginToken{}, aliyunpan.AppConfig{ + AppId: "25dzX3vbYqktVxyX", + DeviceId: "E75459EXhOTkI5ZI6S3qDHA3", + UserId: "", + Nonce: 0, + PublicKey: "", + }, aliyunpan.SessionConfig{ + DeviceName: "Chrome浏览器", + ModelName: "Windows网页版", + }) user, _ := panClient.GetUserInfo() task := &SyncTask{ Id: "5b2d7c10-e927-4e72-8f9d-5abb3bb04814", diff --git a/internal/syncdrive/sync_db_test.go b/internal/syncdrive/sync_db_test.go index 59c4a29..16230d0 100644 --- a/internal/syncdrive/sync_db_test.go +++ b/internal/syncdrive/sync_db_test.go @@ -25,7 +25,16 @@ func TestPanSyncDb(t *testing.T) { } // pan client - panClient := aliyunpan.NewPanClient(*webToken, aliyunpan.AppLoginToken{}) + panClient := aliyunpan.NewPanClient(*webToken, aliyunpan.AppLoginToken{}, aliyunpan.AppConfig{ + AppId: "25dzX3vbYqktVxyX", + DeviceId: "E75459EXhOTkI5ZI6S3qDHA3", + UserId: "", + Nonce: 0, + PublicKey: "", + }, aliyunpan.SessionConfig{ + DeviceName: "Chrome浏览器", + ModelName: "Windows网页版", + }) // get user info ui, err := panClient.GetUserInfo() diff --git a/internal/syncdrive/sync_task_mgr_test.go b/internal/syncdrive/sync_task_mgr_test.go index bb54958..84b4f65 100644 --- a/internal/syncdrive/sync_task_mgr_test.go +++ b/internal/syncdrive/sync_task_mgr_test.go @@ -16,7 +16,16 @@ func TestStart(t *testing.T) { } // pan client - panClient := aliyunpan.NewPanClient(*webToken, aliyunpan.AppLoginToken{}) + panClient := aliyunpan.NewPanClient(*webToken, aliyunpan.AppLoginToken{}, aliyunpan.AppConfig{ + AppId: "25dzX3vbYqktVxyX", + DeviceId: "E75459EXhOTkI5ZI6S3qDHA3", + UserId: "", + Nonce: 0, + PublicKey: "", + }, aliyunpan.SessionConfig{ + DeviceName: "Chrome浏览器", + ModelName: "Windows网页版", + }) user, _ := panClient.GetUserInfo() manager := NewSyncTaskManager( @@ -27,7 +36,7 @@ func TestStart(t *testing.T) { SyncOption{}, ) - manager.Start(nil) + manager.Start(nil, StepSyncFile) time.Sleep(30 * time.Minute) - manager.Stop() + manager.Stop(StepSyncFile) } diff --git a/internal/syncdrive/sync_task_test.go b/internal/syncdrive/sync_task_test.go index 41ec5ee..bf9edc4 100644 --- a/internal/syncdrive/sync_task_test.go +++ b/internal/syncdrive/sync_task_test.go @@ -17,7 +17,16 @@ func TestSyncTask(t *testing.T) { } // pan client - panClient := aliyunpan.NewPanClient(*webToken, aliyunpan.AppLoginToken{}) + panClient := aliyunpan.NewPanClient(*webToken, aliyunpan.AppLoginToken{}, aliyunpan.AppConfig{ + AppId: "25dzX3vbYqktVxyX", + DeviceId: "E75459EXhOTkI5ZI6S3qDHA3", + UserId: "", + Nonce: 0, + PublicKey: "", + }, aliyunpan.SessionConfig{ + DeviceName: "Chrome浏览器", + ModelName: "Windows网页版", + }) user, _ := panClient.GetUserInfo() task := SyncTask{ Id: "5b2d7c10-e927-4e72-8f9d-5abb3bb04814",