Fixed usage and progress display
This commit is contained in:
parent
12f82e106e
commit
3403deb463
5 changed files with 123 additions and 26 deletions
20
chunker.go
20
chunker.go
|
|
@ -17,13 +17,17 @@ type chunker struct {
|
|||
gc *gokapiClient
|
||||
parallelChunks int
|
||||
chunkSize int
|
||||
maxDownloads int
|
||||
maxDays int
|
||||
}
|
||||
|
||||
func newChunker(gc *gokapiClient, parallelChunks, chunkSize int) *chunker {
|
||||
func newChunker(gc *gokapiClient, config Config) *chunker {
|
||||
return &chunker{
|
||||
gc: gc,
|
||||
parallelChunks: parallelChunks,
|
||||
chunkSize: chunkSize,
|
||||
parallelChunks: config.ParallelChunks,
|
||||
chunkSize: config.ChunkSize,
|
||||
maxDownloads: config.MaxDownloads,
|
||||
maxDays: config.MaxDays,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -45,8 +49,8 @@ func (c *chunker) UploadFile(ctx context.Context, filename string, progress func
|
|||
filename: fname,
|
||||
totalSize: fstat.Size(),
|
||||
contentType: mime.TypeByExtension(filepath.Ext(fname)),
|
||||
allowedDownloads: 5,
|
||||
expiryDays: 7,
|
||||
allowedDownloads: c.maxDownloads,
|
||||
expiryDays: c.maxDays,
|
||||
password: "",
|
||||
}
|
||||
|
||||
|
|
@ -61,6 +65,10 @@ func (c *chunker) upload(ctx context.Context, fi uploadInfo, r io.ReaderAt, prog
|
|||
}
|
||||
|
||||
chunks := int(fi.totalSize/int64(c.chunkSize) + 1)
|
||||
uploaders := c.parallelChunks
|
||||
if chunks < uploaders {
|
||||
uploaders = 1
|
||||
}
|
||||
|
||||
chunkUploaded := make(chan uploadedChunk)
|
||||
doneChunkReport := make(chan struct{})
|
||||
|
|
@ -91,7 +99,7 @@ func (c *chunker) upload(ctx context.Context, fi uploadInfo, r io.ReaderAt, prog
|
|||
}()
|
||||
|
||||
errGroup, egctx := errgroup.WithContext(ctx)
|
||||
errGroup.SetLimit(c.parallelChunks)
|
||||
errGroup.SetLimit(uploaders)
|
||||
|
||||
for i := 0; i < chunks; i++ {
|
||||
errGroup.Go(func() error {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue