Skip to content

Commit

Permalink
apply qiniu.upload.v2, change endpoint to fog
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikubill committed Mar 11, 2021
1 parent f30a2da commit 3b86f87
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 104 deletions.
4 changes: 2 additions & 2 deletions downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ func downloadFile(filepath string, url string, bar *pb.ProgressBar) error {
if err := out.Truncate(length); err != nil {
return fmt.Errorf("tmpfile fruncate failed: %s", err)
}
if length > 10*1024*1024 && resp.Header.Get("Accept-Ranges") != "" && runConfig.parallel > 1 {
if length > 10*1024*1024 && resp.Header.Get("Accept-Ranges") != "" && runConfig.parallel > 1 || runConfig.parallel < 1 {
_parallel = runConfig.parallel
}

Expand All @@ -278,7 +278,7 @@ func downloadFile(filepath string, url string, bar *pb.ProgressBar) error {
log.Printf("parallel = %d", _parallel)
log.Printf("block = %d", blk)
}
for i := 0; i <= _parallel; i++ {
for i := 0; i < _parallel; i++ {
wg.Add(1)
start := int64(i) * blk
end := start + blk
Expand Down
9 changes: 5 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ module cowtransfer-uploader
go 1.15

require (
github.com/cheggaaa/pb/v3 v3.0.5
github.com/cheggaaa/pb/v3 v3.0.6
github.com/fatih/color v1.10.0 // indirect
github.com/jessevdk/go-flags v1.4.0 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/orcaman/concurrent-map v0.0.0-20190826125027-8c72a8bb44f6
golang.org/x/sys v0.0.0-20201231184435-2d18734c6014 // indirect
github.com/mattn/go-runewidth v0.0.10 // indirect
github.com/orcaman/concurrent-map v0.0.0-20210106121528-16402b402231
github.com/rivo/uniseg v0.2.0 // indirect
golang.org/x/sys v0.0.0-20210309074719-68d13333faf2 // indirect
)
12 changes: 12 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ github.com/cheggaaa/pb/v3 v3.0.4 h1:QZEPYOj2ix6d5oEg63fbHmpolrnNiwjUsk+h74Yt4bM=
github.com/cheggaaa/pb/v3 v3.0.4/go.mod h1:7rgWxLrAUcFMkvJuv09+DYi7mMUYi8nO9iOWcvGJPfw=
github.com/cheggaaa/pb/v3 v3.0.5 h1:lmZOti7CraK9RSjzExsY53+WWfub9Qv13B5m4ptEoPE=
github.com/cheggaaa/pb/v3 v3.0.5/go.mod h1:X1L61/+36nz9bjIsrDU52qHKOQukUQe2Ge+YvGuquCw=
github.com/cheggaaa/pb/v3 v3.0.6 h1:ULPm1wpzvj60FvmCrX7bIaB80UgbhI+zSaQJKRfCbAs=
github.com/cheggaaa/pb/v3 v3.0.6/go.mod h1:X1L61/+36nz9bjIsrDU52qHKOQukUQe2Ge+YvGuquCw=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s=
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
Expand All @@ -24,8 +26,16 @@ github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Ky
github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.10 h1:CoZ3S2P7pvtP45xOtBw+/mDL2z0RKI576gSkzRRpdGg=
github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
github.com/orcaman/concurrent-map v0.0.0-20190826125027-8c72a8bb44f6 h1:lNCW6THrCKBiJBpz8kbVGjC7MgdCGKwuvBgc7LoD6sw=
github.com/orcaman/concurrent-map v0.0.0-20190826125027-8c72a8bb44f6/go.mod h1:Lu3tH6HLW3feq74c2GC+jIMS/K2CFcDWnWD9XkenwhI=
github.com/orcaman/concurrent-map v0.0.0-20210106121528-16402b402231 h1:fa50YL1pzKW+1SsBnJDOHppJN9stOEwS+CRWyUtyYGU=
github.com/orcaman/concurrent-map v0.0.0-20210106121528-16402b402231/go.mod h1:Lu3tH6HLW3feq74c2GC+jIMS/K2CFcDWnWD9XkenwhI=
github.com/rivo/uniseg v0.1.0 h1:+2KBaVoUmb9XzDsrx/Ct0W/EYOSFf/nWTauy++DprtY=
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand All @@ -42,3 +52,5 @@ golang.org/x/sys v0.0.0-20201207223542-d4d67f95c62d h1:MiWWjyhUzZ+jvhZvloX6ZrUsd
golang.org/x/sys v0.0.0-20201207223542-d4d67f95c62d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201231184435-2d18734c6014 h1:joucsQqXmyBVxViHCPFjG3hx8JzIFSaym3l3MM/Jsdg=
golang.org/x/sys v0.0.0-20201231184435-2d18734c6014/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210309074719-68d13333faf2 h1:46ULzRKLh1CwgRq2dC5SlBzEqqNCi8rreOZnNrbqcIY=
golang.org/x/sys v0.0.0-20210309074719-68d13333faf2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
9 changes: 5 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"bufio"
"flag"
"fmt"
"github.com/cheggaaa/pb/v3"
"log"
"os"
"reflect"
"strings"
"unsafe"

"github.com/cheggaaa/pb/v3"
)

var (
Expand All @@ -26,9 +27,9 @@ type uploadPart struct {

func init() {
addFlag(&runConfig.token, []string{"-cookie", "-c", "--cookie"}, "", "Your User cookie (optional)")
addFlag(&runConfig.parallel, []string{"-parallel", "-p", "--parallel"}, 4, "Parallel task count (default 4)")
addFlag(&runConfig.blockSize, []string{"-block", "-b", "--block"}, 262144, "Upload Block Size (default 262144)")
addFlag(&runConfig.interval, []string{"-timeout", "-t", "--timeout"}, 10, "Request retry/timeout limit (in second, default 10)")
addFlag(&runConfig.parallel, []string{"-parallel", "-p", "--parallel"}, 3, "Parallel task count (default 3)")
addFlag(&runConfig.blockSize, []string{"-block", "-b", "--block"}, 1200000, "Upload Block Size (default 1200000)")
addFlag(&runConfig.interval, []string{"-timeout", "-t", "--timeout"}, 15, "Request retry/timeout limit (in second, default 10)")
addFlag(&runConfig.prefix, []string{"-prefix", "-o", "--output"}, ".", "File download dictionary/name (default \".\")")
addFlag(&runConfig.singleMode, []string{"-single", "-s", "--single"}, false, "Single Upload Mode")
addFlag(&runConfig.debugMode, []string{"-verbose", "-v", "--verbose"}, false, "Verbose Mode")
Expand Down
33 changes: 30 additions & 3 deletions struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ type uploadResult struct {
Key string `json:"key"`
}

type initResp struct {
Token string
TransferGUID string
FileGUID string
EncodeID string
Exp int64 `json:"expireAt"`
ID string `json:"uploadId"`
}

type upResp struct {
Etag string `json:"etag"`
MD5 string `json:"md5"`
}

type prepareSendResp struct {
UploadToken string `json:"uptoken"`
TransferGUID string `json:"transferguid"`
Expand All @@ -31,9 +45,22 @@ type prepareSendResp struct {
ErrorMessage string `json:"error_message"`
}

type uploadResponse struct {
Ticket string `json:"ctx"`
Hash int64 `json:"crc32"`
// type uploadResponse struct {
// Ticket string `json:"ctx"`
// Hash int64 `json:"crc32"`
// }

type slek struct {
ETag string `json:"etag"`
Part int64 `json:"partNumber"`
}

type clds struct {
Parts []slek `json:"parts"`
FName string `json:"fname"`
Mimetype string `json:"mimeType"`
Metadata map[string]string
Vars map[string]string
}

type beforeSendResp struct {
Expand Down
Loading

0 comments on commit 3b86f87

Please sign in to comment.