diff --git a/internal/piwigocli/images.go b/internal/piwigocli/images.go index 047e030..2a53de9 100644 --- a/internal/piwigocli/images.go +++ b/internal/piwigocli/images.go @@ -1,6 +1,7 @@ package piwigocli type ImagesGroup struct { + List ImagesListCommand `command:"list" description:"List of images"` Details ImagesDetailsCommand `command:"details" description:"Details of the images"` Upload ImagesUploadCommand `command:"upload" description:"Upload of an images"` UploadTree ImagesUploadTreeCommand `command:"upload-tree" description:"Upload of a directory of images"` diff --git a/internal/piwigocli/images_list.go b/internal/piwigocli/images_list.go new file mode 100644 index 0000000..8b7bc5e --- /dev/null +++ b/internal/piwigocli/images_list.go @@ -0,0 +1,59 @@ +package piwigocli + +import ( + "fmt" + "net/url" + "strings" + + "github.com/celogeek/piwigo-cli/internal/piwigo" +) + +type ImagesListCommand struct { + Recursive bool `short:"r" long:"recursive" description:"recursive listing"` + CategoryId int `short:"c" long:"category" description:"list for this category" required:"true"` +} + +type ImagesListResult struct { + Images []*piwigo.ImagesDetails `json:"images"` + Pagination struct { + Count int `json:"count"` + Page int `json:"page"` + PerPage int `json:"per_page"` + Total int `json:"total_count"` + } `json:"page"` +} + +func (c *ImagesListCommand) Execute(args []string) error { + p := piwigo.Piwigo{} + if err := p.LoadConfig(); err != nil { + return err + } + + _, err := p.Login() + if err != nil { + return err + } + + var resp ImagesListResult + data := &url.Values{} + data.Set("cat_id", fmt.Sprint(c.CategoryId)) + data.Set("recursive", fmt.Sprintf("%v", c.Recursive)) + if err := p.Post("pwg.categories.getImages", data, &resp); err != nil { + return err + } + + categories, err := p.Categories() + if err != nil { + return err + } + + for _, image := range resp.Images { + for _, category := range image.Categories { + fmt.Printf("%s/%s\n", strings.ReplaceAll(categories[category.Id].Name, " / ", "/"), image.Filename) + } + } + + // piwigo.DumpResponse(resp) + + return nil +}