mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 16:59:12 +00:00
fix: date time and improve erorrs (#22)
This commit is contained in:
parent
c372ca4ddf
commit
d4aa2027c0
13 changed files with 84 additions and 73 deletions
|
@ -2,8 +2,6 @@ package radarr
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
@ -24,7 +22,7 @@ type Config struct {
|
|||
|
||||
type Client interface {
|
||||
Test() (*SystemStatusResponse, error)
|
||||
Push(release Release) error
|
||||
Push(release Release) (bool, error)
|
||||
}
|
||||
|
||||
type client struct {
|
||||
|
@ -70,7 +68,7 @@ type SystemStatusResponse struct {
|
|||
func (c *client) Test() (*SystemStatusResponse, error) {
|
||||
res, err := c.get("system/status")
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("radarr client get error")
|
||||
log.Error().Stack().Err(err).Msg("radarr client get error")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@ -78,14 +76,14 @@ func (c *client) Test() (*SystemStatusResponse, error) {
|
|||
|
||||
body, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("radarr client error reading body")
|
||||
log.Error().Stack().Err(err).Msg("radarr client error reading body")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
response := SystemStatusResponse{}
|
||||
err = json.Unmarshal(body, &response)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("radarr client error json unmarshal")
|
||||
log.Error().Stack().Err(err).Msg("radarr client error json unmarshal")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@ -94,37 +92,42 @@ func (c *client) Test() (*SystemStatusResponse, error) {
|
|||
return &response, nil
|
||||
}
|
||||
|
||||
func (c *client) Push(release Release) error {
|
||||
func (c *client) Push(release Release) (bool, error) {
|
||||
res, err := c.post("release/push", release)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("radarr client post error")
|
||||
return err
|
||||
log.Error().Stack().Err(err).Msg("radarr client post error")
|
||||
return false, err
|
||||
}
|
||||
|
||||
if res == nil {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
defer res.Body.Close()
|
||||
|
||||
body, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("radarr client error reading body")
|
||||
return err
|
||||
log.Error().Stack().Err(err).Msg("radarr client error reading body")
|
||||
return false, err
|
||||
}
|
||||
|
||||
pushResponse := make([]PushResponse, 0)
|
||||
err = json.Unmarshal(body, &pushResponse)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("radarr client error json unmarshal")
|
||||
return err
|
||||
log.Error().Stack().Err(err).Msg("radarr client error json unmarshal")
|
||||
return false, err
|
||||
}
|
||||
|
||||
log.Trace().Msgf("radarr release/push response body: %+v", string(body))
|
||||
log.Trace().Msgf("radarr release/push response body: %+v", body)
|
||||
|
||||
// log and return if rejected
|
||||
if pushResponse[0].Rejected {
|
||||
rejections := strings.Join(pushResponse[0].Rejections, ", ")
|
||||
|
||||
log.Trace().Msgf("radarr push rejected: %s - reasons: %q", release.Title, rejections)
|
||||
return errors.New(fmt.Errorf("radarr push rejected %v", rejections).Error())
|
||||
return false, nil
|
||||
}
|
||||
|
||||
return nil
|
||||
// success true
|
||||
return true, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue