fetch tags

This commit is contained in:
Celogeek 2021-12-31 17:46:31 +01:00
parent 1e948b887e
commit ade03260e2
Signed by: celogeek
GPG Key ID: E6B7BDCFC446233A

View File

@ -26,14 +26,23 @@ func (c *ImagesTagCommand) Execute(args []string) error {
return err return err
} }
var resp piwigotools.ImageDetails var imgDetails piwigotools.ImageDetails
if err := p.Post("pwg.images.getInfo", &url.Values{ if err := p.Post("pwg.images.getInfo", &url.Values{
"image_id": []string{fmt.Sprint(c.Id)}, "image_id": []string{fmt.Sprint(c.Id)},
}, &resp); err != nil { }, &imgDetails); err != nil {
return err return err
} }
img, err := resp.Preview(25) var tags struct {
Tags piwigotools.Tags `json:"tags"`
}
if err := p.Post("pwg.tags.getAdminList", &url.Values{
"image_id": []string{fmt.Sprint(c.Id)},
}, &tags); err != nil {
return err
}
img, err := imgDetails.Preview(25)
if err != nil { if err != nil {
return err return err
} }
@ -41,12 +50,12 @@ func (c *ImagesTagCommand) Execute(args []string) error {
fmt.Println(img) fmt.Println(img)
t := table.NewWriter() t := table.NewWriter()
t.AppendRows([]table.Row{ t.AppendRows([]table.Row{
{"Name", resp.Name}, {"Name", imgDetails.Name},
{"Url", resp.Url}, {"Url", imgDetails.Url},
{"CreatedAt", resp.DateCreation}, {"CreatedAt", imgDetails.DateCreation},
{"Size", fmt.Sprintf("%d x %d", resp.Width, resp.Height)}, {"Size", fmt.Sprintf("%d x %d", imgDetails.Width, imgDetails.Height)},
{"Categories", strings.Join(resp.Categories.Names(), "\n")}, {"Categories", strings.Join(imgDetails.Categories.Names(), "\n")},
{"Tags", strings.Join(resp.Tags.NamesWithAgeAt(resp.DateCreation), "\n")}, {"Tags", strings.Join(imgDetails.Tags.NamesWithAgeAt(&imgDetails.DateCreation), "\n")},
}) })
t.SetOutputMirror(os.Stdout) t.SetOutputMirror(os.Stdout)