start using new upload api

This commit is contained in:
celogeek 2022-05-08 18:12:47 +02:00
parent 46e0ad988b
commit 8c6ef9c3cc
Signed by: celogeek
GPG Key ID: E6B7BDCFC446233A

View File

@ -23,7 +23,12 @@ type UploadCommand struct {
} }
type UploadError struct { type UploadError struct {
Error string Error string `json:"error"`
Status string `json:"string"`
}
type UploadCreate struct {
UploadId string `json:"upload_id"`
} }
type UploadFileRequest struct { type UploadFileRequest struct {
@ -177,11 +182,22 @@ func (c *UploadCommand) FileUpload(sum string) error {
} }
func (c *UploadCommand) Execute(args []string) error { func (c *UploadCommand) Execute(args []string) error {
sum, err := c.FileExists() cli := c.Cli()
resp, err := cli.R().SetError(&UploadError{}).SetResult(&UploadCreate{}).Post("/upload/create")
if err != nil { if err != nil {
return err return err
} }
return c.FileUpload(sum)
if err, ok := resp.Error().(*UploadError); ok {
logger.Println(string(resp.Body()))
logger.Println(resp.Error(), resp.StatusCode(), resp.Header())
return errors.New(err.Error)
}
result := resp.Result().(*UploadCreate)
fmt.Printf("Upload create: %s", result.UploadId)
return nil
} }
func init() { func init() {