From d8e82a7c376e2b09814938d00a9ba77222fd20d5 Mon Sep 17 00:00:00 2001 From: celogeek <65178+celogeek@users.noreply.github.com> Date: Sat, 18 Dec 2021 23:13:03 +0100 Subject: [PATCH] use categories get list instead of admin list --- internal/piwigocli/categories_list.go | 40 ++++++--------------------- 1 file changed, 9 insertions(+), 31 deletions(-) diff --git a/internal/piwigocli/categories_list.go b/internal/piwigocli/categories_list.go index 53dcfc4..6a79c1c 100644 --- a/internal/piwigocli/categories_list.go +++ b/internal/piwigocli/categories_list.go @@ -1,10 +1,8 @@ package piwigocli import ( - "encoding/json" "net/url" "os" - "strconv" "github.com/celogeek/piwigo-cli/internal/piwigo" "github.com/jedib0t/go-pretty/v6/table" @@ -14,33 +12,9 @@ type CategoriesListCommand struct { } type Category struct { - Id int `json:"id,string"` + Id int `json:"id"` Name string `json:"name"` - FullName string `json:"fullname"` - ImagesCount int `json:"nb_images,string"` -} - -func getInt(n interface{}) (r int) { - switch n := n.(type) { - case string: - r, _ = strconv.Atoi(n) - case int: - r = n - } - return -} - -func (b *Category) UnmarshalJSON(data []byte) error { - var v map[string]interface{} - if err := json.Unmarshal(data, &v); err != nil { - return err - } - - b.Id = getInt(v["id"]) - b.Name = v["name"].(string) - b.FullName = v["fullname"].(string) - b.ImagesCount = getInt(v["nb_images"]) - return nil + ImagesCount int `json:"nb_images"` } type GetCategoriesListResponse struct { @@ -59,17 +33,21 @@ func (c *CategoriesListCommand) Execute(args []string) error { } var resp GetCategoriesListResponse - if err := p.Post("pwg.categories.getAdminList", &url.Values{}, &resp); err != nil { + + if err := p.Post("pwg.categories.getList", &url.Values{ + "recursive": []string{"true"}, + "fullname": []string{"true"}, + }, &resp); err != nil { return err } t := table.NewWriter() - t.AppendHeader(table.Row{"Id", "FullName", "ImagesCount"}) + t.AppendHeader(table.Row{"Id", "Name", "Images"}) for _, category := range resp.Categories { t.AppendRow(table.Row{ category.Id, - category.FullName, + category.Name, category.ImagesCount, }) }