Skip to content

Commit

Permalink
Merge branch 'main' into dn2_super
Browse files Browse the repository at this point in the history
  • Loading branch information
davidnewhall committed Nov 15, 2024
2 parents 9f31a53 + c31139e commit 3e21110
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 11 deletions.
4 changes: 2 additions & 2 deletions pkg/apps/radarr.go
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@ func radarrDeleteAllCustomFormats(req *http.Request) (int, interface{}) {
// @Tags Radarr
// @Produce json
// @Param instance path int64 true "instance ID"
// @Success 200 {object} apps.Respond.apiResponse{message=[]radarr.ImportListOutput} "import list list"
// @Success 200 {object} apps.Respond.apiResponse{message=[]radarr.ImportListOutput} "list of import lists"
// @Failure 500 {object} apps.Respond.apiResponse{message=string} "instance error"
// @Failure 404 {object} string "bad token or api key"
// @Router /api/radarr/{instance}/importlist [get]
Expand All @@ -938,7 +938,7 @@ func radarrGetImportLists(req *http.Request) (int, interface{}) {
// @Accept json
// @Param instance path int64 true "instance ID"
// @Param listID path int64 true "Import List ID"
// @Param PUT body radarr.ImportListInput true "Updated Import Listcontent"
// @Param PUT body radarr.ImportListInput true "Updated Import List Content"
// @Success 200 {object} apps.Respond.apiResponse{message=radarr.ImportListOutput} "import list returns"
// @Failure 400 {object} apps.Respond.apiResponse{message=string} "invalid json provided"
// @Failure 500 {object} apps.Respond.apiResponse{message=string} "instance error"
Expand Down
79 changes: 79 additions & 0 deletions pkg/apps/sonarr.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ func (a *Apps) sonarrHandlers() { //nolint:funlen
a.HandleAPIpath(starr.Sonarr, "/customformats/{cfid:[0-9]+}", sonarrUpdateCustomFormat, "PUT")
a.HandleAPIpath(starr.Sonarr, "/customformats/{cfid:[0-9]+}", sonarrDeleteCustomFormat, "DELETE")
a.HandleAPIpath(starr.Sonarr, "/customformats/all", sonarrDeleteAllCustomFormats, "DELETE")
a.HandleAPIpath(starr.Sonarr, "/importlist", sonarrGetImportLists, "GET")
a.HandleAPIpath(starr.Sonarr, "/importlist", sonarrAddImportList, "POST")
a.HandleAPIpath(starr.Sonarr, "/importlist/{ilid:[0-9]+}", sonarrUpdateImportList, "PUT")
a.HandleAPIpath(starr.Sonarr, "/qualitydefinitions", sonarrGetQualityDefinitions, "GET")
a.HandleAPIpath(starr.Sonarr, "/qualitydefinition", sonarrUpdateQualityDefinition, "PUT")
a.HandleAPIpath(starr.Sonarr, "/rootFolder", sonarrRootFolders, "GET")
Expand Down Expand Up @@ -1112,6 +1115,82 @@ func sonarrDeleteAllCustomFormats(req *http.Request) (int, interface{}) {
}
}

// @Description Returns all Import Lists from Sonarr.
// @Summary Get Sonarr Import Lists
// @Tags Sonarr
// @Produce json
// @Param instance path int64 true "instance ID"
// @Success 200 {object} apps.Respond.apiResponse{message=[]sonarr.ImportListOutput} "list of import lists"
// @Failure 500 {object} apps.Respond.apiResponse{message=string} "instance error"
// @Failure 404 {object} string "bad token or api key"
// @Router /api/sonarr/{instance}/importlist [get]
// @Security ApiKeyAuth
func sonarrGetImportLists(req *http.Request) (int, interface{}) {
ilist, err := getSonarr(req).GetImportListsContext(req.Context())
if err != nil {
return apiError(http.StatusInternalServerError, "getting import lists", err)
}

return http.StatusOK, ilist
}

// @Description Updates an Import List in Sonarr.
// @Summary Update Sonarr Import List
// @Tags Sonarr
// @Produce json
// @Accept json
// @Param instance path int64 true "instance ID"
// @Param listID path int64 true "Import List ID"
// @Param PUT body sonarr.ImportListInput true "Updated Import List Content"
// @Success 200 {object} apps.Respond.apiResponse{message=sonarr.ImportListOutput} "import list returns"
// @Failure 400 {object} apps.Respond.apiResponse{message=string} "invalid json provided"
// @Failure 500 {object} apps.Respond.apiResponse{message=string} "instance error"
// @Failure 404 {object} string "bad token or api key"
// @Router /api/sonarr/{instance}/importlist/{listID} [put]
// @Security ApiKeyAuth
func sonarrUpdateImportList(req *http.Request) (int, interface{}) {
var ilist sonarr.ImportListInput
if err := json.NewDecoder(req.Body).Decode(&ilist); err != nil {
return apiError(http.StatusBadRequest, "decoding payload", err)
}

ilist.ID, _ = strconv.ParseInt(mux.Vars(req)["ilid"], mnd.Base10, mnd.Bits64)

output, err := getSonarr(req).UpdateImportListContext(req.Context(), &ilist, false)
if err != nil {
return apiError(http.StatusInternalServerError, "updating import list", err)
}

return http.StatusOK, output
}

// @Description Creates a new Import List in Sonarr.
// @Summary Create Sonarr Import List
// @Tags Sonarr
// @Produce json
// @Accept json
// @Param instance path int64 true "instance ID"
// @Param POST body sonarr.ImportListInput true "New Import List"
// @Success 200 {object} apps.Respond.apiResponse{message=sonarr.ImportListOutput} "import list returns"
// @Failure 400 {object} apps.Respond.apiResponse{message=string} "invalid json provided"
// @Failure 500 {object} apps.Respond.apiResponse{message=string} "instance error"
// @Failure 404 {object} string "bad token or api key"
// @Router /api/sonarr/{instance}/importlist [post]
// @Security ApiKeyAuth
func sonarrAddImportList(req *http.Request) (int, interface{}) {
var ilist sonarr.ImportListInput
if err := json.NewDecoder(req.Body).Decode(&ilist); err != nil {
return apiError(http.StatusBadRequest, "decoding payload", err)
}

output, err := getSonarr(req).AddImportListContext(req.Context(), &ilist)
if err != nil {
return apiError(http.StatusInternalServerError, "creating import list", err)
}

return http.StatusOK, output
}

// @Description Returns all Quality Definitions from Sonarr.
// @Summary Get Sonarr Quality Definitions
// @Tags Sonarr
Expand Down
6 changes: 3 additions & 3 deletions pkg/triggers/cfsync/lidarr.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ func (a *Action) SyncLidarrInstanceCF(event website.EventType, instance int) err
func (c *cmd) syncLidarr(ctx context.Context, input *common.ActionInput) {
info := clientinfo.Get()
if info == nil || len(info.Actions.Sync.LidarrInstances) < 1 {
c.Debugf("[%s requested] Cannot sync Lidarr profiles and formats. Website provided 0 instances.", input.Type)
c.Printf("[%s requested] Cannot sync Lidarr profiles and formats. Website provided 0 instances.", input.Type)
return
} else if len(c.Apps.Lidarr) < 1 {
c.Debugf("[%s requested] Cannot sync Lidarr profiles and formats. No Lidarr instances configured.", input.Type)
c.Printf("[%s requested] Cannot sync Lidarr profiles and formats. No Lidarr instances configured.", input.Type)
return
}

for idx, app := range c.Apps.Lidarr {
instance := idx + 1
if !app.Enabled() || !info.Actions.Sync.LidarrInstances.Has(instance) {
c.Debugf("[%s requested] Profiles and formats sync skipping Lidarr instance %d. Not in sync list: %v",
c.Printf("[%s requested] Profiles and formats sync skipping Lidarr instance %d. Not in sync list: %v",
input.Type, instance, info.Actions.Sync.LidarrInstances)
continue
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/triggers/cfsync/radarr.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ func (a *Action) SyncRadarrInstanceCF(event website.EventType, instance int) err
func (c *cmd) syncRadarr(ctx context.Context, input *common.ActionInput) {
info := clientinfo.Get()
if info == nil || len(info.Actions.Sync.RadarrInstances) < 1 {
c.Debugf("[%s requested] Cannot sync Radarr profiles and formats. Website provided 0 instances.", input.Type)
c.Printf("[%s requested] Cannot sync Radarr profiles and formats. Website provided 0 instances.", input.Type)
return
} else if len(c.Apps.Radarr) < 1 {
c.Debugf("[%s requested] Cannot sync Radarr profiles and formats. No Radarr instances configured.", input.Type)
c.Printf("[%s requested] Cannot sync Radarr profiles and formats. No Radarr instances configured.", input.Type)
return
}

for idx, app := range c.Apps.Radarr {
instance := idx + 1
if !app.Enabled() || !info.Actions.Sync.RadarrInstances.Has(instance) {
c.Debugf("[%s requested] Profiles and formats sync skipping Radarr instance %d. Not in sync list: %v",
c.Printf("[%s requested] Profiles and formats sync skipping Radarr instance %d. Not in sync list: %v",
input.Type, instance, info.Actions.Sync.RadarrInstances)
continue
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/triggers/cfsync/sonarr.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@ func (a *Action) SyncSonarrInstanceRP(event website.EventType, instance int) err
func (c *cmd) syncSonarr(ctx context.Context, input *common.ActionInput) {
info := clientinfo.Get()
if info == nil || len(info.Actions.Sync.SonarrInstances) < 1 {
c.Debugf("[%s requested] Cannot sync Sonarr profiles and formats. Website provided 0 instances.", input.Type)
c.Printf("[%s requested] Cannot sync Sonarr profiles and formats. Website provided 0 instances.", input.Type)
return
} else if len(c.Apps.Sonarr) < 1 {
c.Debugf("[%s requested] Cannot sync Sonarr profiles and formats. No Sonarr instances configured.", input.Type)
c.Printf("[%s requested] Cannot sync Sonarr profiles and formats. No Sonarr instances configured.", input.Type)
return
}

for idx, app := range c.Apps.Sonarr {
instance := idx + 1
if !app.Enabled() || !info.Actions.Sync.SonarrInstances.Has(instance) {
c.Debugf("[%s requested] Profiles and formats sync skipping Sonarr instance %d. Not in sync list: %v",
c.Printf("[%s requested] Profiles and formats sync skipping Sonarr instance %d. Not in sync list: %v",
input.Type, instance, info.Actions.Sync.SonarrInstances)
continue
}
Expand Down

0 comments on commit 3e21110

Please sign in to comment.