feat(actions): qbit add options content layout and skip hash check (#393)

* feat(actions): qbit content layout and skip hash check

* feat(actions): qbit options
This commit is contained in:
ze0s 2022-08-02 18:06:45 +02:00 committed by GitHub
parent db9d048f5d
commit 9508cbb46c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 394 additions and 50 deletions

View file

@ -1,5 +1,9 @@
package qbittorrent
import (
"strconv"
)
type Torrent struct {
AddedOn int `json:"added_on"`
AmountLeft int `json:"amount_left"`
@ -216,3 +220,68 @@ type TransferInfo struct {
UpInfoSpeed int64 `json:"up_info_speed"`
UpRateLimit int64 `json:"up_rate_limit"`
}
type ContentLayout string
const (
ContentLayoutOriginal ContentLayout = "ORIGINAL"
ContentLayoutSubfolderNone ContentLayout = "SUBFOLDER_NONE"
ContentLayoutSubfolderCreate ContentLayout = "SUBFOLDER_CREATE"
)
type TorrentAddOptions struct {
Paused *bool
SkipHashCheck *bool
ContentLayout *ContentLayout
SavePath *string
AutoTMM *bool
Category *string
Tags *string
LimitUploadSpeed *int64
LimitDownloadSpeed *int64
LimitRatio *float64
LimitSeedTime *int64
}
func (o *TorrentAddOptions) Prepare() map[string]string {
options := map[string]string{}
if o.Paused != nil {
options["paused"] = "true"
}
if o.SkipHashCheck != nil {
options["skip_checking"] = "true"
}
if o.ContentLayout != nil {
if *o.ContentLayout == ContentLayoutSubfolderCreate {
options["root_folder"] = "true"
} else if *o.ContentLayout == ContentLayoutSubfolderNone {
options["root_folder"] = "false"
}
// if ORIGINAL then leave empty
}
if o.SavePath != nil && *o.SavePath != "" {
options["savepath"] = *o.SavePath
options["autoTMM"] = "false"
}
if o.Category != nil && *o.Category != "" {
options["category"] = *o.Category
}
if o.Tags != nil && *o.Tags != "" {
options["tags"] = *o.Tags
}
if o.LimitUploadSpeed != nil && *o.LimitUploadSpeed > 0 {
options["upLimit"] = strconv.FormatInt(*o.LimitUploadSpeed*1000, 10)
}
if o.LimitDownloadSpeed != nil && *o.LimitDownloadSpeed > 0 {
options["dlLimit"] = strconv.FormatInt(*o.LimitDownloadSpeed*1000, 10)
}
if o.LimitRatio != nil && *o.LimitRatio > 0 {
options["ratioLimit"] = strconv.FormatFloat(*o.LimitRatio, 'f', 2, 64)
}
if o.LimitSeedTime != nil && *o.LimitSeedTime > 0 {
options["seedingTimeLimit"] = strconv.FormatInt(*o.LimitSeedTime, 10)
}
return options
}

View file

@ -0,0 +1,177 @@
package qbittorrent
import (
"testing"
"github.com/stretchr/testify/assert"
)
func PtrBool(b bool) *bool {
return &b
}
func PtrStr(s string) *string {
return &s
}
func PtrInt64(i int64) *int64 {
return &i
}
func PtrFloat64(f float64) *float64 {
return &f
}
func TestTorrentAddOptions_Prepare(t *testing.T) {
layoutNone := ContentLayoutSubfolderNone
layoutCreate := ContentLayoutSubfolderCreate
layoutOriginal := ContentLayoutOriginal
type fields struct {
Paused *bool
SkipHashCheck *bool
ContentLayout *ContentLayout
SavePath *string
AutoTMM *bool
Category *string
Tags *string
LimitUploadSpeed *int64
LimitDownloadSpeed *int64
LimitRatio *float64
LimitSeedTime *int64
}
tests := []struct {
name string
fields fields
want map[string]string
}{
{
name: "test_01",
fields: fields{
Paused: nil,
SkipHashCheck: PtrBool(true),
ContentLayout: nil,
SavePath: PtrStr("/home/test/torrents"),
AutoTMM: nil,
Category: PtrStr("test"),
Tags: PtrStr("limited,slow"),
LimitUploadSpeed: PtrInt64(100000),
LimitDownloadSpeed: PtrInt64(100000),
LimitRatio: PtrFloat64(2.0),
LimitSeedTime: PtrInt64(100),
},
want: map[string]string{
"skip_checking": "true",
"autoTMM": "false",
"ratioLimit": "2.00",
"savepath": "/home/test/torrents",
"seedingTimeLimit": "100",
"category": "test",
"tags": "limited,slow",
"upLimit": "100000000",
"dlLimit": "100000000",
},
},
{
name: "test_02",
fields: fields{
Paused: nil,
SkipHashCheck: PtrBool(true),
ContentLayout: &layoutCreate,
SavePath: PtrStr("/home/test/torrents"),
AutoTMM: nil,
Category: PtrStr("test"),
Tags: PtrStr("limited,slow"),
LimitUploadSpeed: PtrInt64(100000),
LimitDownloadSpeed: PtrInt64(100000),
LimitRatio: PtrFloat64(2.0),
LimitSeedTime: PtrInt64(100),
},
want: map[string]string{
"skip_checking": "true",
"root_folder": "true",
"autoTMM": "false",
"ratioLimit": "2.00",
"savepath": "/home/test/torrents",
"seedingTimeLimit": "100",
"category": "test",
"tags": "limited,slow",
"upLimit": "100000000",
"dlLimit": "100000000",
},
},
{
name: "test_03",
fields: fields{
Paused: nil,
SkipHashCheck: PtrBool(true),
ContentLayout: &layoutNone,
SavePath: PtrStr("/home/test/torrents"),
AutoTMM: nil,
Category: PtrStr("test"),
Tags: PtrStr("limited,slow"),
LimitUploadSpeed: PtrInt64(100000),
LimitDownloadSpeed: PtrInt64(100000),
LimitRatio: PtrFloat64(2.0),
LimitSeedTime: PtrInt64(100),
},
want: map[string]string{
"skip_checking": "true",
"root_folder": "false",
"autoTMM": "false",
"ratioLimit": "2.00",
"savepath": "/home/test/torrents",
"seedingTimeLimit": "100",
"category": "test",
"tags": "limited,slow",
"upLimit": "100000000",
"dlLimit": "100000000",
},
},
{
name: "test_04",
fields: fields{
Paused: nil,
SkipHashCheck: PtrBool(true),
ContentLayout: &layoutOriginal,
SavePath: PtrStr("/home/test/torrents"),
AutoTMM: nil,
Category: PtrStr("test"),
Tags: PtrStr("limited,slow"),
LimitUploadSpeed: PtrInt64(100000),
LimitDownloadSpeed: PtrInt64(100000),
LimitRatio: PtrFloat64(2.0),
LimitSeedTime: PtrInt64(100),
},
want: map[string]string{
"skip_checking": "true",
"autoTMM": "false",
"ratioLimit": "2.00",
"savepath": "/home/test/torrents",
"seedingTimeLimit": "100",
"category": "test",
"tags": "limited,slow",
"upLimit": "100000000",
"dlLimit": "100000000",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
o := &TorrentAddOptions{
Paused: tt.fields.Paused,
SkipHashCheck: tt.fields.SkipHashCheck,
ContentLayout: tt.fields.ContentLayout,
SavePath: tt.fields.SavePath,
AutoTMM: tt.fields.AutoTMM,
Category: tt.fields.Category,
Tags: tt.fields.Tags,
LimitUploadSpeed: tt.fields.LimitUploadSpeed,
LimitDownloadSpeed: tt.fields.LimitDownloadSpeed,
LimitRatio: tt.fields.LimitRatio,
LimitSeedTime: tt.fields.LimitSeedTime,
}
got := o.Prepare()
assert.Equal(t, tt.want, got)
})
}
}