feat: add bandwidth limiting support to file transfers with UI controls
Release / release (pull_request) Successful in 1m7s
Release / release (pull_request) Successful in 1m7s
This commit is contained in:
@@ -167,7 +167,7 @@ func (a *App) Delete(connId, path string) error {
|
||||
return exp.Delete(path)
|
||||
}
|
||||
|
||||
func (a *App) QueueTransfer(id string, srcConnId, dstConnId, srcPath, dstPath, filename string, size int64, verify bool) error {
|
||||
func (a *App) QueueTransfer(id string, srcConnId, dstConnId, srcPath, dstPath, filename string, size int64, verify bool, limitMBps int) error {
|
||||
srcExp, err := a.getExplorerForConnection(srcConnId)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -185,7 +185,7 @@ func (a *App) QueueTransfer(id string, srcConnId, dstConnId, srcPath, dstPath, f
|
||||
return err
|
||||
}
|
||||
|
||||
return a.transferManager.QueueTransfer(id, srcPath, dstPath, filename, size, srcExp, dstExp, verify)
|
||||
return a.transferManager.QueueTransfer(id, srcPath, dstPath, filename, size, srcExp, dstExp, verify, limitMBps)
|
||||
}
|
||||
|
||||
func (a *App) GetTransfers() []*transfer.Transfer {
|
||||
@@ -232,7 +232,7 @@ func (a *App) PromptUploadFiles(connId, destPath string) error {
|
||||
remotePath = destPath + fileName
|
||||
}
|
||||
|
||||
a.QueueTransfer(id, "local", connId, localPath, remotePath, fileName, stat.Size(), false)
|
||||
a.QueueTransfer(id, "local", connId, localPath, remotePath, fileName, stat.Size(), false, 0)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -272,7 +272,7 @@ func (a *App) PromptUploadDirectory(connId, destPath string) error {
|
||||
}
|
||||
|
||||
id := uuid.New().String()
|
||||
a.QueueTransfer(id, "local", connId, path, remotePath, info.Name(), info.Size(), false)
|
||||
a.QueueTransfer(id, "local", connId, path, remotePath, info.Name(), info.Size(), false, 0)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -304,7 +304,7 @@ func (a *App) PromptDownload(connId, remotePath string) error {
|
||||
size = stat.Size
|
||||
}
|
||||
|
||||
return a.QueueTransfer(id, connId, "local", remotePath, localPath, fileName, size, false)
|
||||
return a.QueueTransfer(id, connId, "local", remotePath, localPath, fileName, size, false, 0)
|
||||
}
|
||||
|
||||
type TransferItem struct {
|
||||
@@ -314,7 +314,7 @@ type TransferItem struct {
|
||||
Size int64 `json:"size"`
|
||||
}
|
||||
|
||||
func (a *App) TransferItems(srcConnId, dstConnId, dstPath string, items []TransferItem, verify bool) error {
|
||||
func (a *App) TransferItems(srcConnId, dstConnId, dstPath string, items []TransferItem, verify bool, limitMBps int) error {
|
||||
for _, item := range items {
|
||||
if !item.IsDir {
|
||||
id := uuid.New().String()
|
||||
@@ -328,18 +328,18 @@ func (a *App) TransferItems(srcConnId, dstConnId, dstPath string, items []Transf
|
||||
remotePath = dstPath + item.Name
|
||||
}
|
||||
|
||||
if err := a.QueueTransfer(id, srcConnId, dstConnId, item.Path, remotePath, item.Name, item.Size, verify); err != nil {
|
||||
if err := a.QueueTransfer(id, srcConnId, dstConnId, item.Path, remotePath, item.Name, item.Size, verify, limitMBps); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
// Run remote walk in goroutine to not block UI
|
||||
go a.transferRemoteDirectory(srcConnId, dstConnId, item.Path, dstPath, verify)
|
||||
go a.transferRemoteDirectory(srcConnId, dstConnId, item.Path, dstPath, verify, limitMBps)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) transferRemoteDirectory(srcConnId, dstConnId, srcDirPath, dstBasePath string, verify bool) {
|
||||
func (a *App) transferRemoteDirectory(srcConnId, dstConnId, srcDirPath, dstBasePath string, verify bool, limitMBps int) {
|
||||
baseName := filepath.Base(srcDirPath)
|
||||
|
||||
newDstPath := dstBasePath
|
||||
@@ -360,11 +360,11 @@ func (a *App) transferRemoteDirectory(srcConnId, dstConnId, srcDirPath, dstBaseP
|
||||
|
||||
for _, entry := range entries {
|
||||
if entry.IsDir {
|
||||
a.transferRemoteDirectory(srcConnId, dstConnId, entry.Path, newDstPath, verify)
|
||||
a.transferRemoteDirectory(srcConnId, dstConnId, entry.Path, newDstPath, verify, limitMBps)
|
||||
} else {
|
||||
id := uuid.New().String()
|
||||
itemDstPath := newDstPath + "/" + entry.Name
|
||||
a.QueueTransfer(id, srcConnId, dstConnId, entry.Path, itemDstPath, entry.Name, entry.Size, verify)
|
||||
a.QueueTransfer(id, srcConnId, dstConnId, entry.Path, itemDstPath, entry.Name, entry.Size, verify, limitMBps)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user