0.2.63 update
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/ponzischeme89/memby/server/internal/store"
|
||||
)
|
||||
|
||||
type arrIntegrationStatus struct {
|
||||
SonarrConfigured bool `json:"sonarrConfigured"`
|
||||
RadarrConfigured bool `json:"radarrConfigured"`
|
||||
SonarrEnabled bool `json:"sonarrEnabled"`
|
||||
RadarrEnabled bool `json:"radarrEnabled"`
|
||||
}
|
||||
|
||||
func (s *Server) arrIntegrationStatus(r *http.Request) arrIntegrationStatus {
|
||||
policy, err := s.store.ArrIntegrationPolicy(r.Context())
|
||||
if err != nil {
|
||||
policy = store.DefaultArrIntegrationPolicy()
|
||||
}
|
||||
return arrIntegrationStatus{SonarrConfigured: s.sonarr != nil, RadarrConfigured: s.radarr != nil, SonarrEnabled: s.sonarr != nil && policy.SonarrEnabled, RadarrEnabled: s.radarr != nil && policy.RadarrEnabled}
|
||||
}
|
||||
|
||||
func (s *Server) handleAdminArrIntegrations(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == http.MethodGet {
|
||||
writeJSON(w, http.StatusOK, s.arrIntegrationStatus(r))
|
||||
return
|
||||
}
|
||||
var req struct {
|
||||
SonarrEnabled bool `json:"sonarrEnabled"`
|
||||
RadarrEnabled bool `json:"radarrEnabled"`
|
||||
}
|
||||
if err := json.NewDecoder(http.MaxBytesReader(w, r.Body, 4<<10)).Decode(&req); err != nil {
|
||||
writeError(w, http.StatusBadRequest, "malformed request body")
|
||||
return
|
||||
}
|
||||
if err := s.store.SetArrIntegrationPolicy(r.Context(), store.ArrIntegrationPolicy{SonarrEnabled: req.SonarrEnabled, RadarrEnabled: req.RadarrEnabled}); err != nil {
|
||||
writeError(w, http.StatusInternalServerError, "could not save integration settings")
|
||||
return
|
||||
}
|
||||
s.loggerFor(r.Context()).Info("arr integrations changed", "sonarr_enabled", req.SonarrEnabled, "radarr_enabled", req.RadarrEnabled)
|
||||
writeJSON(w, http.StatusOK, s.arrIntegrationStatus(r))
|
||||
}
|
||||
Reference in New Issue
Block a user