From f6e99297c3b1f30921dd72d9493faa481934e805 Mon Sep 17 00:00:00 2001 From: NullpointerW <825708370@qq.com> Date: Wed, 21 Jun 2023 16:59:13 +0800 Subject: [PATCH] add Category apis --- apiv2_test.go | 22 ++++++++++++++++++++++ torrents.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/apiv2_test.go b/apiv2_test.go index c857df6..beb1143 100644 --- a/apiv2_test.go +++ b/apiv2_test.go @@ -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) + } +} diff --git a/torrents.go b/torrents.go index 66319c8..8f08070 100644 --- a/torrents.go +++ b/torrents.go @@ -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 +}