mirror of
https://github.com/dutchcoders/transfer.sh.git
synced 2024-11-29 23:50:18 +01:00
Add gdrive-chunk-size
This commit is contained in:
parent
5310566b81
commit
5fa36e25c8
3 changed files with 15 additions and 4 deletions
|
@ -129,6 +129,7 @@ bucket | aws bucket | | BUCKET
|
||||||
basedir | path storage for local/gdrive provider| |
|
basedir | path storage for local/gdrive provider| |
|
||||||
gdrive-client-json-filepath | path to oauth client json config for gdrive provider| |
|
gdrive-client-json-filepath | path to oauth client json config for gdrive provider| |
|
||||||
gdrive-local-config-path | path to store local transfer.sh config cache for gdrive provider| |
|
gdrive-local-config-path | path to store local transfer.sh config cache for gdrive provider| |
|
||||||
|
gdrive-chunk-size | chunk size for gdrive upload in megabytes, must be lower than available memory (8 MB) | |
|
||||||
lets-encrypt-hosts | hosts to use for lets encrypt certificates (comma seperated) | |
|
lets-encrypt-hosts | hosts to use for lets encrypt certificates (comma seperated) | |
|
||||||
log | path to log file| |
|
log | path to log file| |
|
||||||
|
|
||||||
|
|
10
cmd/cmd.go
10
cmd/cmd.go
|
@ -11,6 +11,7 @@ import (
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
"github.com/minio/cli"
|
"github.com/minio/cli"
|
||||||
"log"
|
"log"
|
||||||
|
"google.golang.org/api/googleapi"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Version = "0.1"
|
var Version = "0.1"
|
||||||
|
@ -126,6 +127,11 @@ var globalFlags = []cli.Flag{
|
||||||
Usage: "",
|
Usage: "",
|
||||||
Value: "",
|
Value: "",
|
||||||
},
|
},
|
||||||
|
cli.IntFlag{
|
||||||
|
Name: "gdrive-chunk-size",
|
||||||
|
Usage: "",
|
||||||
|
Value: googleapi.DefaultUploadChunkSize,
|
||||||
|
},
|
||||||
cli.IntFlag{
|
cli.IntFlag{
|
||||||
Name: "rate-limit",
|
Name: "rate-limit",
|
||||||
Usage: "requests per minute",
|
Usage: "requests per minute",
|
||||||
|
@ -294,13 +300,15 @@ func New() *Cmd {
|
||||||
options = append(options, server.UseStorage(storage))
|
options = append(options, server.UseStorage(storage))
|
||||||
}
|
}
|
||||||
case "gdrive":
|
case "gdrive":
|
||||||
|
chunkSize := c.Int("gdrive-chunk-size")
|
||||||
|
|
||||||
if clientJsonFilepath := c.String("gdrive-client-json-filepath"); clientJsonFilepath == "" {
|
if clientJsonFilepath := c.String("gdrive-client-json-filepath"); clientJsonFilepath == "" {
|
||||||
panic("client-json-filepath not set.")
|
panic("client-json-filepath not set.")
|
||||||
} else if localConfigPath := c.String("gdrive-local-config-path"); localConfigPath == "" {
|
} else if localConfigPath := c.String("gdrive-local-config-path"); localConfigPath == "" {
|
||||||
panic("local-config-path not set.")
|
panic("local-config-path not set.")
|
||||||
} else if basedir := c.String("basedir"); basedir == "" {
|
} else if basedir := c.String("basedir"); basedir == "" {
|
||||||
panic("basedir not set.")
|
panic("basedir not set.")
|
||||||
} else if storage, err := server.NewGDriveStorage(clientJsonFilepath, localConfigPath, basedir, logger); err != nil {
|
} else if storage, err := server.NewGDriveStorage(clientJsonFilepath, localConfigPath, basedir, chunkSize, logger); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
} else {
|
} else {
|
||||||
options = append(options, server.UseStorage(storage))
|
options = append(options, server.UseStorage(storage))
|
||||||
|
|
|
@ -321,10 +321,11 @@ type GDrive struct {
|
||||||
rootId string
|
rootId string
|
||||||
basedir string
|
basedir string
|
||||||
localConfigPath string
|
localConfigPath string
|
||||||
|
chunkSize int
|
||||||
logger *log.Logger
|
logger *log.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGDriveStorage(clientJsonFilepath string, localConfigPath string, basedir string, logger *log.Logger) (*GDrive, error) {
|
func NewGDriveStorage(clientJsonFilepath string, localConfigPath string, basedir string, chunkSize int, logger *log.Logger) (*GDrive, error) {
|
||||||
b, err := ioutil.ReadFile(clientJsonFilepath)
|
b, err := ioutil.ReadFile(clientJsonFilepath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -341,7 +342,8 @@ func NewGDriveStorage(clientJsonFilepath string, localConfigPath string, basedir
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
storage := &GDrive{service: srv, basedir: basedir, rootId: "", localConfigPath: localConfigPath, logger: logger}
|
chunkSize = chunkSize * 1024 * 1024
|
||||||
|
storage := &GDrive{service: srv, basedir: basedir, rootId: "", localConfigPath: localConfigPath, chunkSize: chunkSize, logger: logger}
|
||||||
err = storage.setupRoot()
|
err = storage.setupRoot()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -561,7 +563,7 @@ func (s *GDrive) Put(token string, filename string, reader io.Reader, contentTyp
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
_, err = s.service.Files.Create(dst).Context(ctx).Media(reader).Do()
|
_, err = s.service.Files.Create(dst).Context(ctx).Media(reader, googleapi.ChunkSize(s.chunkSize)).Do()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in a new issue