mirror of
https://github.com/celogeek/piwigo-cli.git
synced 2025-05-25 18:22:37 +02:00
use categories get list instead of admin list
This commit is contained in:
parent
2889e94dd9
commit
d8e82a7c37
@ -1,10 +1,8 @@
|
|||||||
package piwigocli
|
package piwigocli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"github.com/celogeek/piwigo-cli/internal/piwigo"
|
"github.com/celogeek/piwigo-cli/internal/piwigo"
|
||||||
"github.com/jedib0t/go-pretty/v6/table"
|
"github.com/jedib0t/go-pretty/v6/table"
|
||||||
@ -14,33 +12,9 @@ type CategoriesListCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Category struct {
|
type Category struct {
|
||||||
Id int `json:"id,string"`
|
Id int `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
FullName string `json:"fullname"`
|
ImagesCount int `json:"nb_images"`
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetCategoriesListResponse struct {
|
type GetCategoriesListResponse struct {
|
||||||
@ -59,17 +33,21 @@ func (c *CategoriesListCommand) Execute(args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var resp GetCategoriesListResponse
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
t := table.NewWriter()
|
t := table.NewWriter()
|
||||||
|
|
||||||
t.AppendHeader(table.Row{"Id", "FullName", "ImagesCount"})
|
t.AppendHeader(table.Row{"Id", "Name", "Images"})
|
||||||
for _, category := range resp.Categories {
|
for _, category := range resp.Categories {
|
||||||
t.AppendRow(table.Row{
|
t.AppendRow(table.Row{
|
||||||
category.Id,
|
category.Id,
|
||||||
category.FullName,
|
category.Name,
|
||||||
category.ImagesCount,
|
category.ImagesCount,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user