mirror of
https://github.com/celogeek/piwigo-cli.git
synced 2025-05-25 10:12:37 +02:00
debug output
This commit is contained in:
parent
29880be5b6
commit
025991160b
@ -1,10 +1,13 @@
|
||||
package piwigo
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@ -54,10 +57,27 @@ func (p *Piwigo) Post(method string, form *url.Values, resp interface{}) error {
|
||||
Result: resp,
|
||||
}
|
||||
|
||||
if os.Getenv("DEBUG") == "1" {
|
||||
newBody := &bytes.Buffer{}
|
||||
tee := io.TeeReader(r.Body, newBody)
|
||||
|
||||
var RawResult map[string]interface{}
|
||||
err = json.NewDecoder(tee).Decode(&RawResult)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
DumpResponse(RawResult)
|
||||
|
||||
err = json.NewDecoder(newBody).Decode(&Result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
err = json.NewDecoder(r.Body).Decode(&Result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if Result.Stat != "ok" {
|
||||
return fmt.Errorf("[Error %d] %s", Result.Err, Result.ErrMessage)
|
||||
|
@ -1,6 +1,7 @@
|
||||
package piwigocli
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"os"
|
||||
|
||||
"github.com/celogeek/piwigo-cli/internal/piwigo"
|
||||
@ -29,7 +30,7 @@ func (c *GetInfosCommand) Execute(args []string) error {
|
||||
|
||||
var resp GetInfosResponse
|
||||
|
||||
if err := p.Post("pwg.getInfos", nil, &resp); err != nil {
|
||||
if err := p.Post("pwg.getInfos", &url.Values{}, &resp); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -48,5 +49,4 @@ func (c *GetInfosCommand) Execute(args []string) error {
|
||||
|
||||
func init() {
|
||||
parser.AddCommand("getinfos", "Get general information", "", &getInfosCommand)
|
||||
|
||||
}
|
||||
|
@ -6,7 +6,8 @@ import (
|
||||
"github.com/jessevdk/go-flags"
|
||||
)
|
||||
|
||||
type Options struct{}
|
||||
type Options struct {
|
||||
}
|
||||
|
||||
var options Options
|
||||
|
||||
|
@ -8,21 +8,21 @@ import (
|
||||
)
|
||||
|
||||
type LoginCommand struct {
|
||||
Url string `short:"u" long:"url" description:"Url of the instance"`
|
||||
Login string `short:"l" long:"login" description:"Login"`
|
||||
Password string `short:"p" long:"password" description:"Password"`
|
||||
Url string `short:"u" long:"url" description:"Url of the instance" required:"true"`
|
||||
Login string `short:"l" long:"login" description:"Login" required:"true"`
|
||||
Password string `short:"p" long:"password" description:"Password" required:"true"`
|
||||
}
|
||||
|
||||
func (c *LoginCommand) Execute(args []string) error {
|
||||
fmt.Printf("Login on %s...\n", c.Url)
|
||||
|
||||
Piwigo := piwigo.Piwigo{
|
||||
p := piwigo.Piwigo{
|
||||
Url: c.Url,
|
||||
}
|
||||
|
||||
result := false
|
||||
|
||||
err := Piwigo.Post("pwg.session.login", &url.Values{
|
||||
err := p.Post("pwg.session.login", &url.Values{
|
||||
"username": []string{c.Login},
|
||||
"password": []string{c.Password},
|
||||
}, &result)
|
||||
@ -30,7 +30,7 @@ func (c *LoginCommand) Execute(args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
err = Piwigo.SaveConfig()
|
||||
err = p.SaveConfig()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -17,14 +17,14 @@ type StatusResponse struct {
|
||||
}
|
||||
|
||||
func (c *StatusCommand) Execute(args []string) error {
|
||||
Piwigo := piwigo.Piwigo{}
|
||||
if err := Piwigo.LoadConfig(); err != nil {
|
||||
p := piwigo.Piwigo{}
|
||||
if err := p.LoadConfig(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
resp := &StatusResponse{}
|
||||
|
||||
if err := Piwigo.Post("pwg.session.getStatus", nil, &resp); err != nil {
|
||||
if err := p.Post("pwg.session.getStatus", nil, &resp); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user