Skip to content

Commit

Permalink
add Category apis
Browse files Browse the repository at this point in the history
  • Loading branch information
NullpointerW committed Jun 21, 2023
1 parent 5d437fa commit f6e9929
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
22 changes: 22 additions & 0 deletions apiv2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,25 @@ func TestRenameFile(t *testing.T) {
t.Error(err)
}
}

func TestAddCategory(t *testing.T) {
cli, err := NewCli("http://localhost:8991")
if err != nil {
panic(err)
}
err = cli.AddCategory("test", "")
if err != nil {
t.Error(err)
}
}

func TestRmCategoies(t *testing.T) {
cli, err := NewCli("http://localhost:8991")
if err != nil {
panic(err)
}
err = cli.RmCategoies("test")
if err != nil {
t.Error(err)
}
}
30 changes: 30 additions & 0 deletions torrents.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,33 @@ func (c *Client) RenameFile(hash, old, new string) error {
ignrBody(resp.Body)
return nil
}

func (c *Client) AddCategory(categoryName, savePath string) error {
opt := Optional{
"category": categoryName,
}
if savePath != "" {
opt["savePath"] = savePath
}
resp, err := c.postXwwwFormUrlencoded("torrents/createCategory", opt)
err = RespOk(resp, err)
if err != nil {
return err
}
ignrBody(resp.Body)
return nil
}

func (c *Client) RmCategoies(categories ...string) error {
categs := strings.Join(categories, "\n")
opt := Optional{
"categories": categs,
}
resp, err := c.postXwwwFormUrlencoded("torrents/removeCategories", opt)
err = RespOk(resp, err)
if err != nil {
return err
}
ignrBody(resp.Body)
return nil
}

0 comments on commit f6e9929

Please sign in to comment.