Skip to content

Commit 324a275

Browse files
authored
Merge branch 'main' into feat/chunk
2 parents 439c3c1 + 04a5e58 commit 324a275

File tree

8 files changed

+287
-69
lines changed

8 files changed

+287
-69
lines changed

drivers/189pc/utils.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -472,14 +472,16 @@ func (y *Cloud189PC) refreshSession() (err error) {
472472
// 普通上传
473473
// 无法上传大小为0的文件
474474
func (y *Cloud189PC) StreamUpload(ctx context.Context, dstDir model.Obj, file model.FileStreamer, up driver.UpdateProgress, isFamily bool, overwrite bool) (model.Obj, error) {
475-
size := file.GetSize()
476-
sliceSize := min(size, partSize(size))
475+
// 文件大小
476+
fileSize := file.GetSize()
477+
// 分片大小,不得为文件大小
478+
sliceSize := partSize(fileSize)
477479

478480
params := Params{
479481
"parentFolderId": dstDir.GetID(),
480482
"fileName": url.QueryEscape(file.GetName()),
481-
"fileSize": fmt.Sprint(file.GetSize()),
482-
"sliceSize": fmt.Sprint(sliceSize),
483+
"fileSize": fmt.Sprint(fileSize),
484+
"sliceSize": fmt.Sprint(sliceSize), // 必须为特定分片大小
483485
"lazyCheck": "1",
484486
}
485487

@@ -512,10 +514,10 @@ func (y *Cloud189PC) StreamUpload(ctx context.Context, dstDir model.Obj, file mo
512514
retry.DelayType(retry.BackOffDelay))
513515

514516
count := 1
515-
if size > sliceSize {
516-
count = int((size + sliceSize - 1) / sliceSize)
517+
if fileSize > sliceSize {
518+
count = int((fileSize + sliceSize - 1) / sliceSize)
517519
}
518-
lastPartSize := size % sliceSize
520+
lastPartSize := fileSize % sliceSize
519521
if lastPartSize == 0 {
520522
lastPartSize = sliceSize
521523
}
@@ -535,9 +537,9 @@ func (y *Cloud189PC) StreamUpload(ctx context.Context, dstDir model.Obj, file mo
535537
break
536538
}
537539
offset := int64((i)-1) * sliceSize
538-
size := sliceSize
540+
partSize := sliceSize
539541
if i == count {
540-
size = lastPartSize
542+
partSize = lastPartSize
541543
}
542544
partInfo := ""
543545
var reader *stream.SectionReader
@@ -546,14 +548,14 @@ func (y *Cloud189PC) StreamUpload(ctx context.Context, dstDir model.Obj, file mo
546548
Before: func(ctx context.Context) error {
547549
if reader == nil {
548550
var err error
549-
reader, err = ss.GetSectionReader(offset, size)
551+
reader, err = ss.GetSectionReader(offset, partSize)
550552
if err != nil {
551553
return err
552554
}
553555
silceMd5.Reset()
554556
w, err := utils.CopyWithBuffer(writers, reader)
555-
if w != size {
556-
return fmt.Errorf("failed to read all data: (expect =%d, actual =%d) %w", size, w, err)
557+
if w != partSize {
558+
return fmt.Errorf("failed to read all data: (expect =%d, actual =%d) %w", partSize, w, err)
557559
}
558560
// 计算块md5并进行hex和base64编码
559561
md5Bytes := silceMd5.Sum(nil)
@@ -595,7 +597,7 @@ func (y *Cloud189PC) StreamUpload(ctx context.Context, dstDir model.Obj, file mo
595597
fileMd5Hex = strings.ToUpper(hex.EncodeToString(fileMd5.Sum(nil)))
596598
}
597599
sliceMd5Hex := fileMd5Hex
598-
if file.GetSize() > sliceSize {
600+
if fileSize > sliceSize {
599601
sliceMd5Hex = strings.ToUpper(utils.GetMD5EncodeStr(strings.Join(silceMd5Hexs, "\n")))
600602
}
601603

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)