Skip to content

Commit 3bd0ff4

Browse files
authored
Merge pull request #301 from YangSen-qn/dev
support resume api v2
2 parents ac3a079 + fe481b1 commit 3bd0ff4

25 files changed

+402
-118
lines changed

cmd/asyncfetch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"strconv"
77
"time"
88

9-
"github.com/qiniu/api.v7/v7/storage"
9+
"github.com/qiniu/go-sdk/v7/storage"
1010
"github.com/qiniu/qshell/v2/iqshell"
1111
"github.com/spf13/cobra"
1212
)

cmd/cdn.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"time"
1010

1111
"github.com/astaxie/beego/logs"
12-
"github.com/qiniu/api.v7/v7/cdn"
12+
"github.com/qiniu/go-sdk/v7/cdn"
1313
"github.com/qiniu/qshell/v2/iqshell"
1414
"github.com/spf13/cobra"
1515
)

cmd/putfile.go

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"strings"
88
"time"
99

10-
"github.com/qiniu/api.v7/v7/storage"
10+
"github.com/qiniu/go-sdk/v7/storage"
1111
"github.com/qiniu/qshell/v2/iqshell"
1212
"github.com/spf13/cobra"
1313
)
@@ -19,6 +19,7 @@ var upSettings = storage.Settings{
1919
}
2020

2121
var (
22+
isResumeV2 bool
2223
pOverwrite bool
2324
mimeType string
2425
fileType int
@@ -52,6 +53,7 @@ func init() {
5253
formPutCmd.Flags().StringVarP(&callbackUrls, "callback-urls", "l", "", "upload callback urls, separated by comma")
5354
formPutCmd.Flags().StringVarP(&callbackHost, "callback-host", "T", "", "upload callback host")
5455

56+
RePutCmd.Flags().BoolVarP(&isResumeV2, "v2", "", false, "use resumable upload v2 APIs to upload")
5557
RePutCmd.Flags().BoolVarP(&pOverwrite, "overwrite", "w", false, "overwrite mode")
5658
RePutCmd.Flags().StringVarP(&mimeType, "mimetype", "t", "", "file mime type")
5759
RePutCmd.Flags().IntVarP(&fileType, "storage", "s", 0, "storage type")
@@ -224,20 +226,13 @@ func ResumablePut(cmd *cobra.Command, params []string) {
224226
policy.CallbackBodyType = "application/x-www-form-urlencoded"
225227
}
226228

227-
var putExtra storage.RputExtra
228229
var upHost string
229230

230231
if rupHost == "" {
231232
upHost = iqshell.UpHost()
232233
} else {
233234
upHost = rupHost
234235
}
235-
putExtra = storage.RputExtra{
236-
UpHost: upHost,
237-
}
238-
if mimeType != "" {
239-
putExtra.MimeType = mimeType
240-
}
241236

242237
mac, err := iqshell.GetMac()
243238
if err != nil {
@@ -252,8 +247,31 @@ func ResumablePut(cmd *cobra.Command, params []string) {
252247

253248
fmt.Printf("Uploading %s => %s : %s ...\n", localFile, bucket, key)
254249

255-
resume_uploader := storage.NewResumeUploader(nil)
256-
err = resume_uploader.PutFile(context.Background(), &putRet, uptoken, key, localFile, &putExtra)
250+
if isResumeV2 {
251+
252+
resume_uploader := storage.NewResumeUploaderV2(nil)
253+
254+
putExtra := storage.RputV2Extra{
255+
UpHost: upHost,
256+
}
257+
if mimeType != "" {
258+
putExtra.MimeType = mimeType
259+
}
260+
261+
err = resume_uploader.PutFile(context.Background(), &putRet, uptoken, key, localFile, &putExtra)
262+
} else {
263+
264+
resume_uploader := storage.NewResumeUploader(nil)
265+
266+
putExtra := storage.RputExtra{
267+
UpHost: upHost,
268+
}
269+
if mimeType != "" {
270+
putExtra.MimeType = mimeType
271+
}
272+
273+
err = resume_uploader.PutFile(context.Background(), &putRet, uptoken, key, localFile, &putExtra)
274+
}
257275

258276
fmt.Println()
259277
if err != nil {

cmd/qupload.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"strings"
1010

1111
"github.com/astaxie/beego/logs"
12-
"github.com/qiniu/api.v7/v7/storage"
12+
"github.com/qiniu/go-sdk/v7/storage"
1313
"github.com/qiniu/qshell/v2/iqshell"
1414
"github.com/spf13/cobra"
1515
)

cmd/qupload2.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"strings"
77

88
"github.com/astaxie/beego/logs"
9-
"github.com/qiniu/api.v7/v7/storage"
9+
"github.com/qiniu/go-sdk/v7/storage"
1010
"github.com/qiniu/qshell/v2/iqshell"
1111
"github.com/spf13/cobra"
1212
)
@@ -25,6 +25,7 @@ var (
2525

2626
func init() {
2727
qUpload2Cmd.Flags().Int64Var(&up2threadCount, "thread-count", 0, "multiple thread count")
28+
qUpload2Cmd.Flags().BoolVarP(&uploadConfig.ResumableAPIV2, "resumable-api-v2", "", false, "use resumable upload v2 APIs to upload")
2829
qUpload2Cmd.Flags().StringVar(&uploadConfig.SrcDir, "src-dir", "", "src dir to upload")
2930
qUpload2Cmd.Flags().StringVar(&uploadConfig.FileList, "file-list", "", "file list to upload")
3031
qUpload2Cmd.Flags().StringVar(&uploadConfig.Bucket, "bucket", "", "bucket")

cmd/root.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99

1010
"github.com/astaxie/beego/logs"
1111
homedir "github.com/mitchellh/go-homedir"
12-
"github.com/qiniu/api.v7/v7/client"
13-
"github.com/qiniu/api.v7/v7/storage"
12+
"github.com/qiniu/go-sdk/v7/client"
13+
"github.com/qiniu/go-sdk/v7/storage"
1414
"github.com/qiniu/qshell/v2/iqshell"
1515
"github.com/spf13/cobra"
1616
"github.com/spf13/viper"

cmd/rs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"strings"
88
"time"
99

10-
"github.com/qiniu/api.v7/v7/storage"
10+
"github.com/qiniu/go-sdk/v7/storage"
1111
"github.com/qiniu/qshell/v2/iqshell"
1212
"github.com/spf13/cobra"
1313
)

cmd/rsbatch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"sync"
1212
"time"
1313

14-
"github.com/qiniu/api.v7/v7/storage"
14+
"github.com/qiniu/go-sdk/v7/storage"
1515
"github.com/qiniu/qshell/v2/iqshell"
1616
"github.com/spf13/cobra"
1717
)

cmd/sync.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ var (
2323
)
2424

2525
func init() {
26+
syncCmd.Flags().BoolVarP(&isResumeV2, "resumable-api-v2", "", false, "use resumable upload v2 APIs to upload")
2627
syncCmd.Flags().StringVarP(&upHostIp, "uphost", "u", "", "upload host")
2728
syncCmd.Flags().StringVarP(&saveKey, "key", "k", "", "save as <key> in bucket")
2829
RootCmd.AddCommand(syncCmd)
@@ -50,7 +51,7 @@ func Sync(cmd *cobra.Command, params []string) {
5051
bm := iqshell.GetBucketManager()
5152
//sync
5253
tStart := time.Now()
53-
syncRet, sErr := bm.Sync(srcResUrl, bucket, key, upHostIp)
54+
syncRet, sErr := bm.Sync(srcResUrl, bucket, key, upHostIp, isResumeV2)
5455
if sErr != nil {
5556
logs.Error(sErr)
5657
os.Exit(iqshell.STATUS_ERROR)

cmd/token.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import (
1010
"os"
1111
"strings"
1212

13-
"github.com/qiniu/api.v7/v7/auth/qbox"
14-
"github.com/qiniu/api.v7/v7/conf"
15-
"github.com/qiniu/api.v7/v7/storage"
13+
"github.com/qiniu/go-sdk/v7/auth/qbox"
14+
"github.com/qiniu/go-sdk/v7/conf"
15+
"github.com/qiniu/go-sdk/v7/storage"
1616
"github.com/qiniu/qshell/v2/iqshell"
1717
"github.com/spf13/cobra"
1818
)

0 commit comments

Comments
 (0)