Skip to content

Commit 4f2de93

Browse files
CaspianGUANxrgzs
andauthored
feat(degoo): token improvement (#1149)
* Update driver.go Signed-off-by: Caspian <[email protected]> * Update meta.go Signed-off-by: Caspian <[email protected]> * Update util.go Signed-off-by: Caspian <[email protected]> * Update util.go Signed-off-by: Caspian <[email protected]> * Update util.go Signed-off-by: Caspian <[email protected]> * Update util.go Signed-off-by: MadDogOwner <[email protected]> * make account optional * ensure username and password Signed-off-by: MadDogOwner <[email protected]> --------- Signed-off-by: Caspian <[email protected]> Signed-off-by: MadDogOwner <[email protected]> Co-authored-by: MadDogOwner <[email protected]>
1 parent b0dbbeb commit 4f2de93

File tree

4 files changed

+267
-51
lines changed

4 files changed

+267
-51
lines changed

drivers/degoo/driver.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,9 @@ func (d *Degoo) Init(ctx context.Context) error {
3232

3333
d.client = base.HttpClient
3434

35-
if d.Token == "" {
36-
err := d.login(ctx)
37-
if err != nil {
38-
return err
39-
}
35+
// Ensure we have a valid token (will login if needed or refresh if expired)
36+
if err := d.ensureValidToken(ctx); err != nil {
37+
return fmt.Errorf("failed to initialize token: %w", err)
4038
}
4139

4240
return d.getDevices(ctx)
@@ -87,7 +85,7 @@ func (d *Degoo) MakeDir(ctx context.Context, parentDir model.Obj, dirName string
8785
const query = `mutation SetUploadFile3($Token: String!, $FileInfos: [FileInfoUpload3]!) { setUploadFile3(Token: $Token, FileInfos: $FileInfos) }`
8886

8987
variables := map[string]interface{}{
90-
"Token": d.Token,
88+
"Token": d.AccessToken,
9189
"FileInfos": []map[string]interface{}{
9290
{
9391
"Checksum": folderChecksum,
@@ -111,7 +109,7 @@ func (d *Degoo) Move(ctx context.Context, srcObj, dstDir model.Obj) (model.Obj,
111109
const query = `mutation SetMoveFile($Token: String!, $Copy: Boolean, $NewParentID: String!, $FileIDs: [String]!) { setMoveFile(Token: $Token, Copy: $Copy, NewParentID: $NewParentID, FileIDs: $FileIDs) }`
112110

113111
variables := map[string]interface{}{
114-
"Token": d.Token,
112+
"Token": d.AccessToken,
115113
"Copy": false,
116114
"NewParentID": dstDir.GetID(),
117115
"FileIDs": []string{srcObj.GetID()},
@@ -129,7 +127,7 @@ func (d *Degoo) Rename(ctx context.Context, srcObj model.Obj, newName string) er
129127
const query = `mutation SetRenameFile($Token: String!, $FileRenames: [FileRenameInfo]!) { setRenameFile(Token: $Token, FileRenames: $FileRenames) }`
130128

131129
variables := map[string]interface{}{
132-
"Token": d.Token,
130+
"Token": d.AccessToken,
133131
"FileRenames": []DegooFileRenameInfo{
134132
{
135133
ID: srcObj.GetID(),
@@ -155,7 +153,7 @@ func (d *Degoo) Remove(ctx context.Context, obj model.Obj) error {
155153
const query = `mutation SetDeleteFile5($Token: String!, $IsInRecycleBin: Boolean!, $IDs: [IDType]!) { setDeleteFile5(Token: $Token, IsInRecycleBin: $IsInRecycleBin, IDs: $IDs) }`
156154

157155
variables := map[string]interface{}{
158-
"Token": d.Token,
156+
"Token": d.AccessToken,
159157
"IsInRecycleBin": false,
160158
"IDs": []map[string]string{{"FileID": obj.GetID()}},
161159
}

drivers/degoo/meta.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import (
77

88
type Addition struct {
99
driver.RootID
10-
Username string `json:"username" required:"true" help:"Your Degoo account email"`
11-
Password string `json:"password" required:"true" help:"Your Degoo account password"`
12-
Token string `json:"token" help:"Access token for Degoo API, will be obtained automatically if not provided"`
10+
Username string `json:"username" help:"Your Degoo account email"`
11+
Password string `json:"password" help:"Your Degoo account password"`
12+
RefreshToken string `json:"refresh_token" help:"Refresh token for automatic token renewal, obtained automatically"`
13+
AccessToken string `json:"access_token" help:"Access token for Degoo API, obtained automatically"`
1314
}
1415

1516
var config = driver.Config{

drivers/degoo/upload.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func (d *Degoo) getBucketWriteAuth4(ctx context.Context, file model.FileStreamer
4949
}`
5050

5151
variables := map[string]interface{}{
52-
"Token": d.Token,
52+
"Token": d.AccessToken,
5353
"ParentID": parentID,
5454
"StorageUploadInfos": []map[string]string{{
5555
"FileName": file.GetName(),
@@ -174,7 +174,7 @@ func (d *Degoo) SetUploadFile3(ctx context.Context, file model.FileStreamer, par
174174
}`
175175

176176
variables := map[string]interface{}{
177-
"Token": d.Token,
177+
"Token": d.AccessToken,
178178
"FileInfos": []map[string]string{{
179179
"Checksum": checksum,
180180
"CreationTime": strconv.FormatInt(file.CreateTime().UnixMilli(), 10),

0 commit comments

Comments
 (0)