Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: firstLastPiecePrio #25

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ type TorrentAddOptions struct {
LimitRatio float64
LimitSeedTime int64
Rename string
FirstLastPiecePrio bool
}

func (o *TorrentAddOptions) Prepare() map[string]string {
Expand Down Expand Up @@ -329,6 +330,8 @@ func (o *TorrentAddOptions) Prepare() map[string]string {
options["rename"] = o.Rename
}

options["firstLastPiecePrio"] = strconv.FormatBool(o.FirstLastPiecePrio)

return options
}

Expand Down
149 changes: 94 additions & 55 deletions domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func TestTorrentAddOptions_Prepare(t *testing.T) {
LimitRatio float64
LimitSeedTime int64
Rename string
FirstLastPiecePrio bool
}
tests := []struct {
name string
Expand All @@ -42,16 +43,17 @@ func TestTorrentAddOptions_Prepare(t *testing.T) {
LimitSeedTime: 100,
},
want: map[string]string{
"paused": "false",
"skip_checking": "true",
"autoTMM": "false",
"ratioLimit": "2.00",
"savepath": "/home/test/torrents",
"seedingTimeLimit": "100",
"category": "test",
"tags": "limited,slow",
"upLimit": "102400000",
"dlLimit": "102400000",
"paused": "false",
"skip_checking": "true",
"autoTMM": "false",
"firstLastPiecePrio": "false",
"ratioLimit": "2.00",
"savepath": "/home/test/torrents",
"seedingTimeLimit": "100",
"category": "test",
"tags": "limited,slow",
"upLimit": "102400000",
"dlLimit": "102400000",
},
},
{
Expand All @@ -70,18 +72,19 @@ func TestTorrentAddOptions_Prepare(t *testing.T) {
LimitSeedTime: 100,
},
want: map[string]string{
"paused": "false",
"skip_checking": "true",
"root_folder": "true",
"contentLayout": "Subfolder",
"autoTMM": "false",
"ratioLimit": "2.00",
"savepath": "/home/test/torrents",
"seedingTimeLimit": "100",
"category": "test",
"tags": "limited,slow",
"upLimit": "102400000",
"dlLimit": "102400000",
"paused": "false",
"skip_checking": "true",
"root_folder": "true",
"contentLayout": "Subfolder",
"autoTMM": "false",
"firstLastPiecePrio": "false",
"ratioLimit": "2.00",
"savepath": "/home/test/torrents",
"seedingTimeLimit": "100",
"category": "test",
"tags": "limited,slow",
"upLimit": "102400000",
"dlLimit": "102400000",
},
},
{
Expand All @@ -100,18 +103,19 @@ func TestTorrentAddOptions_Prepare(t *testing.T) {
LimitSeedTime: 100,
},
want: map[string]string{
"paused": "false",
"skip_checking": "true",
"root_folder": "false",
"contentLayout": "NoSubfolder",
"autoTMM": "false",
"ratioLimit": "2.00",
"savepath": "/home/test/torrents",
"seedingTimeLimit": "100",
"category": "test",
"tags": "limited,slow",
"upLimit": "102400000",
"dlLimit": "102400000",
"paused": "false",
"skip_checking": "true",
"root_folder": "false",
"contentLayout": "NoSubfolder",
"autoTMM": "false",
"firstLastPiecePrio": "false",
"ratioLimit": "2.00",
"savepath": "/home/test/torrents",
"seedingTimeLimit": "100",
"category": "test",
"tags": "limited,slow",
"upLimit": "102400000",
"dlLimit": "102400000",
},
},
{
Expand All @@ -130,16 +134,17 @@ func TestTorrentAddOptions_Prepare(t *testing.T) {
LimitSeedTime: 100,
},
want: map[string]string{
"paused": "false",
"skip_checking": "true",
"autoTMM": "false",
"ratioLimit": "2.00",
"savepath": "/home/test/torrents",
"seedingTimeLimit": "100",
"category": "test",
"tags": "limited,slow",
"upLimit": "102400000",
"dlLimit": "102400000",
"paused": "false",
"skip_checking": "true",
"autoTMM": "false",
"firstLastPiecePrio": "false",
"ratioLimit": "2.00",
"savepath": "/home/test/torrents",
"seedingTimeLimit": "100",
"category": "test",
"tags": "limited,slow",
"upLimit": "102400000",
"dlLimit": "102400000",
},
},
{
Expand All @@ -159,17 +164,50 @@ func TestTorrentAddOptions_Prepare(t *testing.T) {
Rename: "test-torrent-rename",
},
want: map[string]string{
"paused": "false",
"skip_checking": "true",
"autoTMM": "false",
"ratioLimit": "2.00",
"savepath": "/home/test/torrents",
"seedingTimeLimit": "100",
"category": "test",
"tags": "limited,slow",
"upLimit": "102400000",
"dlLimit": "102400000",
"rename": "test-torrent-rename",
"paused": "false",
"skip_checking": "true",
"autoTMM": "false",
"firstLastPiecePrio": "false",
"ratioLimit": "2.00",
"savepath": "/home/test/torrents",
"seedingTimeLimit": "100",
"category": "test",
"tags": "limited,slow",
"upLimit": "102400000",
"dlLimit": "102400000",
"rename": "test-torrent-rename",
},
},
{
name: "test_06",
fields: fields{
Paused: false,
SkipHashCheck: true,
ContentLayout: ContentLayoutOriginal,
SavePath: "/home/test/torrents",
AutoTMM: false,
FirstLastPiecePrio: true,
Category: "test",
Tags: "limited,slow",
LimitUploadSpeed: 100000,
LimitDownloadSpeed: 100000,
LimitRatio: 2.0,
LimitSeedTime: 100,
Rename: "test-torrent-rename",
},
want: map[string]string{
"paused": "false",
"skip_checking": "true",
"autoTMM": "false",
"firstLastPiecePrio": "true",
"ratioLimit": "2.00",
"savepath": "/home/test/torrents",
"seedingTimeLimit": "100",
"category": "test",
"tags": "limited,slow",
"upLimit": "102400000",
"dlLimit": "102400000",
"rename": "test-torrent-rename",
},
},
}
Expand All @@ -188,6 +226,7 @@ func TestTorrentAddOptions_Prepare(t *testing.T) {
LimitRatio: tt.fields.LimitRatio,
LimitSeedTime: tt.fields.LimitSeedTime,
Rename: tt.fields.Rename,
FirstLastPiecePrio: tt.fields.FirstLastPiecePrio,
}

got := o.Prepare()
Expand Down
27 changes: 27 additions & 0 deletions methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,33 @@ func (c *Client) IncreasePriorityCtx(ctx context.Context, hashes []string) error
return nil
}

// ToggleFirstLastPiecePrio toggles the priority of the first and last pieces of torrents specified by hashes
func (c *Client) ToggleFirstLastPiecePrio(hashes []string) error {
return c.ToggleFirstLastPiecePrioCtx(context.Background(), hashes)
}

// ToggleFirstLastPiecePrioCtx toggles the priority of the first and last pieces of torrents specified by hashes
func (c *Client) ToggleFirstLastPiecePrioCtx(ctx context.Context, hashes []string) error {
hv := strings.Join(hashes, "|")

opts := map[string]string{
"hashes": hv,
}

resp, err := c.postCtx(ctx, "torrents/toggleFirstLastPiecePrio", opts)
if err != nil {
return errors.Wrap(err, "could not toggle first/last piece priority for torrents: %v", hashes)
}

defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return errors.New("unexpected status while toggling first/last piece priority for torrents: %v, status: %d", hashes, resp.StatusCode)
}

return nil
}

func (c *Client) GetAppVersion() (string, error) {
return c.GetAppVersionCtx(context.Background())
}
Expand Down
Loading