Skip to content

Commit

Permalink
feat(downloadclients): qBit add rule UploadSpeedThreshold (#633)
Browse files Browse the repository at this point in the history
feat(downloadclients): qbit add rule upload speed threshold
  • Loading branch information
zze0s committed Jan 8, 2023
1 parent 6194ca9 commit d437f84
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
25 changes: 19 additions & 6 deletions internal/action/qbittorrent.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package action

import (
"context"
"fmt"

"github.com/autobrr/autobrr/internal/domain"
"github.com/autobrr/autobrr/pkg/errors"
Expand Down Expand Up @@ -125,18 +126,30 @@ func (s *service) qbittorrentCheckRulesCanDownload(ctx context.Context, action *
// if current transfer speed is more than threshold return out and skip
// DlInfoSpeed is in bytes so lets convert to KB to match DownloadSpeedThreshold
if info.DlInfoSpeed/1024 >= client.Settings.Rules.DownloadSpeedThreshold {
s.log.Debug().Msg("max active downloads reached, skipping")
rejection := fmt.Sprintf("max active downloads reached and total download speed above threshold: %d, skipping", client.Settings.Rules.DownloadSpeedThreshold)

rejections := []string{"max active downloads reached, skipping"}
return rejections, nil
s.log.Debug().Msg(rejection)

return []string{rejection}, nil
}

// if current transfer speed is more than threshold return out and skip
// UpInfoSpeed is in bytes so lets convert to KB to match UploadSpeedThreshold
if info.UpInfoSpeed/1024 >= client.Settings.Rules.UploadSpeedThreshold {
rejection := fmt.Sprintf("max active downloads reached and total upload speed above threshold: %d, skipping", client.Settings.Rules.UploadSpeedThreshold)

s.log.Debug().Msg(rejection)

return []string{rejection}, nil
}

s.log.Debug().Msg("active downloads are slower than set limit, lets add it")
} else {
s.log.Debug().Msg("max active downloads reached, skipping")
rejection := "max active downloads reached, skipping"

s.log.Debug().Msg(rejection)

rejections := []string{"max active downloads reached, skipping"}
return rejections, nil
return []string{rejection}, nil
}
}
}
Expand Down
1 change: 1 addition & 0 deletions internal/domain/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type DownloadClientRules struct {
MaxActiveDownloads int `json:"max_active_downloads"`
IgnoreSlowTorrents bool `json:"ignore_slow_torrents"`
DownloadSpeedThreshold int64 `json:"download_speed_threshold"`
UploadSpeedThreshold int64 `json:"upload_speed_threshold"`
}

type BasicAuth struct {
Expand Down
20 changes: 14 additions & 6 deletions web/src/forms/settings/DownloadClientForms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,20 @@ function FormFieldsRules() {
/>

{settings.rules?.ignore_slow_torrents === true && (
<NumberFieldWide
name="settings.rules.download_speed_threshold"
label="Download speed threshold"
placeholder="in KB/s"
help="If download speed is below this when max active downloads is hit, download anyways. KB/s"
/>
<>
<NumberFieldWide
name="settings.rules.download_speed_threshold"
label="Download speed threshold"
placeholder="in KB/s"
help="If download speed is below this when max active downloads is hit, download anyways. KB/s"
/>
<NumberFieldWide
name="settings.rules.upload_speed_threshold"
label="Upload speed threshold"
placeholder="in KB/s"
help="If upload speed is below this when max active downloads is hit, download anyways. KB/s"
/>
</>
)}
</>
)}
Expand Down
1 change: 1 addition & 0 deletions web/src/types/Download.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ interface DownloadClientRules {
max_active_downloads: number;
ignore_slow_torrents: boolean;
download_speed_threshold: number;
upload_speed_threshold: number;
}

interface DownloadClientBasicAuth {
Expand Down

0 comments on commit d437f84

Please sign in to comment.