Skip to content

Commit

Permalink
Merge pull request #163 from Notifiarr/unstable
Browse files Browse the repository at this point in the history
Add contexts from end to end, and fix dynamic menus
  • Loading branch information
davidnewhall authored Jan 15, 2022
2 parents 9ffa5cd + 3f5cde0 commit 6cae10b
Show file tree
Hide file tree
Showing 20 changed files with 447 additions and 426 deletions.
24 changes: 12 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ go 1.17

// home grown goodness.
require (
golift.io/cnfg v0.1.1-0.20220103045145-0c0d80e8da3f
golift.io/cnfg v0.1.1
golift.io/deluge v0.9.4-0.20220103091211-1842b313e264
golift.io/qbit v0.0.0-20211121074815-1558e8969b98
golift.io/rotatorr v0.0.0-20210307012029-65b11a8ea8f9
golift.io/starr v0.12.2-0.20220103050138-44b7a8ef1c52
golift.io/starr v0.13.0
golift.io/version v0.0.2
golift.io/xtractr v0.0.11
)
Expand All @@ -21,8 +21,8 @@ require (
github.com/getlantern/context v0.0.0-20190109183933-c447772a6520 // indirect
github.com/getlantern/errors v1.0.1 // indirect
github.com/getlantern/golog v0.0.0-20211223150227-d4d95a44d873 // indirect
github.com/getlantern/hex v0.0.0-20190417191902-c6586a6fe0b7 // indirect
github.com/getlantern/hidden v0.0.0-20201229170000-e66e7f878730 // indirect
github.com/getlantern/hex v0.0.0-20220104173244-ad7e4b9194dc // indirect
github.com/getlantern/hidden v0.0.0-20220104173330-f221c5a24770 // indirect
github.com/getlantern/ops v0.0.0-20200403153110-8476b16edcd6 // indirect
github.com/getlantern/systray v1.1.0
github.com/go-ole/go-ole v1.2.6 // indirect
Expand All @@ -37,13 +37,13 @@ require (

// snapshot and other stuff.
require (
github.com/BurntSushi/toml v0.4.1 // indirect
github.com/BurntSushi/toml v1.0.0 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-sql-driver/mysql v1.6.0
github.com/go-stack/stack v1.8.1 // indirect
github.com/google/cabbie v1.0.3 // indirect
github.com/google/glazier v0.0.0-20211231114135-27694aeee4d5 // indirect
github.com/gopherjs/gopherjs v0.0.0-20211228203721-be292294a697 // indirect
github.com/google/glazier v0.0.0-20220110212823-8a7f3dacb8be // indirect
github.com/gopherjs/gopherjs v0.0.0-20220104163920-15ed2e8cf2bd // indirect
github.com/gopherjs/gopherwasm v1.1.0 // indirect
github.com/gorilla/mux v1.8.0
github.com/hako/durafmt v0.0.0-20210608085754-5c1018a4e16b
Expand All @@ -64,8 +64,8 @@ require (
github.com/tklauser/go-sysconf v0.3.9 // indirect
github.com/tklauser/numcpus v0.3.0 // indirect
golang.org/x/mod v0.5.1
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e
golang.org/x/net v0.0.0-20220114011407-0dd24b26b47d // indirect
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
howett.net/plist v1.0.0 // indirect
Expand All @@ -88,17 +88,17 @@ require (
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.7.0 // indirect
go.uber.org/zap v1.19.1 // indirect
go.uber.org/zap v1.20.0 // indirect
golang.org/x/tools v0.1.8 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
lukechampine.com/uint128 v1.1.1 // indirect
lukechampine.com/uint128 v1.2.0 // indirect
modernc.org/cc/v3 v3.35.22 // indirect
modernc.org/ccgo/v3 v3.14.0 // indirect
modernc.org/libc v1.13.2 // indirect
modernc.org/mathutil v1.4.1 // indirect
modernc.org/memory v1.0.5 // indirect
modernc.org/opt v0.1.1 // indirect
modernc.org/sqlite v1.14.3
modernc.org/sqlite v1.14.4
modernc.org/strutil v1.1.1 // indirect
modernc.org/token v1.0.0 // indirect
)
72 changes: 32 additions & 40 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/apps/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func (a *Apps) Respond(w http.ResponseWriter, stat int, msg interface{}) { //nol

err := json.Encode(map[string]interface{}{"status": statusTxt, "message": msg})
if err != nil {
a.ErrorLog.Printf("JSON response failed. Status: %s, Error: %v, Message: %v", statusTxt, err, msg)
a.ErrorLog.Printf("Sending JSON response failed. Status: %s, Error: %v, Message: %v", statusTxt, err, msg)
}
}

Expand Down
39 changes: 20 additions & 19 deletions pkg/apps/lidarr.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//nolint:dupl
package apps

import (
Expand Down Expand Up @@ -99,14 +100,14 @@ func lidarrAddAlbum(req *http.Request) (int, interface{}) {

app := getLidarr(req)
// Check for existing album.
m, err := app.GetAlbum(payload.ForeignAlbumID)
m, err := app.GetAlbumContext(req.Context(), payload.ForeignAlbumID)
if err != nil {
return http.StatusServiceUnavailable, fmt.Errorf("checking album: %w", err)
} else if len(m) > 0 {
return http.StatusConflict, lidarrData(m[0])
}

album, err := app.AddAlbum(&payload)
album, err := app.AddAlbumContext(req.Context(), &payload)
if err != nil {
return http.StatusInternalServerError, fmt.Errorf("adding album: %w", err)
}
Expand All @@ -117,7 +118,7 @@ func lidarrAddAlbum(req *http.Request) (int, interface{}) {
func lidarrGetArtist(req *http.Request) (int, interface{}) {
artistID, _ := strconv.ParseInt(mux.Vars(req)["artistid"], mnd.Base10, mnd.Bits64)

artist, err := getLidarr(req).GetArtistByID(artistID)
artist, err := getLidarr(req).GetArtistByIDContext(req.Context(), artistID)
if err != nil {
return http.StatusServiceUnavailable, fmt.Errorf("checking artist: %w", err)
}
Expand All @@ -141,7 +142,7 @@ func lidarrData(album *lidarr.Album) map[string]interface{} {
func lidarrCheckAlbum(req *http.Request) (int, interface{}) {
id := mux.Vars(req)["mbid"]

m, err := getLidarr(req).GetAlbum(id)
m, err := getLidarr(req).GetAlbumContext(req.Context(), id)
if err != nil {
return http.StatusServiceUnavailable, fmt.Errorf("checking album: %w", err)
} else if len(m) > 0 {
Expand All @@ -154,7 +155,7 @@ func lidarrCheckAlbum(req *http.Request) (int, interface{}) {
func lidarrGetAlbum(req *http.Request) (int, interface{}) {
albumID, _ := strconv.ParseInt(mux.Vars(req)["albumid"], mnd.Base10, mnd.Bits64)

album, err := getLidarr(req).GetAlbumByID(albumID)
album, err := getLidarr(req).GetAlbumByIDContext(req.Context(), albumID)
if err != nil {
return http.StatusServiceUnavailable, fmt.Errorf("checking album: %w", err)
}
Expand All @@ -165,7 +166,7 @@ func lidarrGetAlbum(req *http.Request) (int, interface{}) {
func lidarrTriggerSearchAlbum(req *http.Request) (int, interface{}) {
albumID, _ := strconv.ParseInt(mux.Vars(req)["albumid"], mnd.Base10, mnd.Bits64)

output, err := getLidarr(req).SendCommand(&lidarr.CommandRequest{
output, err := getLidarr(req).SendCommandContext(req.Context(), &lidarr.CommandRequest{
Name: "AlbumSearch",
AlbumIDs: []int64{albumID},
})
Expand All @@ -177,7 +178,7 @@ func lidarrTriggerSearchAlbum(req *http.Request) (int, interface{}) {
}

func lidarrMetadata(req *http.Request) (int, interface{}) {
profiles, err := getLidarr(req).GetMetadataProfiles()
profiles, err := getLidarr(req).GetMetadataProfilesContext(req.Context())
if err != nil {
return http.StatusInternalServerError, fmt.Errorf("getting profiles: %w", err)
}
Expand All @@ -193,7 +194,7 @@ func lidarrMetadata(req *http.Request) (int, interface{}) {

func lidarrQualityDefs(req *http.Request) (int, interface{}) {
// Get the profiles from lidarr.
definitions, err := getLidarr(req).GetQualityDefinition()
definitions, err := getLidarr(req).GetQualityDefinitionContext(req.Context())
if err != nil {
return http.StatusInternalServerError, fmt.Errorf("getting profiles: %w", err)
}
Expand All @@ -209,7 +210,7 @@ func lidarrQualityDefs(req *http.Request) (int, interface{}) {

func lidarrQualityProfiles(req *http.Request) (int, interface{}) {
// Get the profiles from lidarr.
profiles, err := getLidarr(req).GetQualityProfiles()
profiles, err := getLidarr(req).GetQualityProfilesContext(req.Context())
if err != nil {
return http.StatusInternalServerError, fmt.Errorf("getting profiles: %w", err)
}
Expand All @@ -225,7 +226,7 @@ func lidarrQualityProfiles(req *http.Request) (int, interface{}) {

func lidarrGetQualityProfile(req *http.Request) (int, interface{}) {
// Get the profiles from lidarr.
profiles, err := getLidarr(req).GetQualityProfiles()
profiles, err := getLidarr(req).GetQualityProfilesContext(req.Context())
if err != nil {
return http.StatusInternalServerError, fmt.Errorf("getting profiles: %w", err)
}
Expand All @@ -243,7 +244,7 @@ func lidarrAddQualityProfile(req *http.Request) (int, interface{}) {
}

// Get the profiles from radarr.
id, err := getLidarr(req).AddQualityProfile(&profile)
id, err := getLidarr(req).AddQualityProfileContext(req.Context(), &profile)
if err != nil {
return http.StatusInternalServerError, fmt.Errorf("adding profile: %w", err)
}
Expand All @@ -266,7 +267,7 @@ func lidarrUpdateQualityProfile(req *http.Request) (int, interface{}) {
}

// Get the profiles from radarr.
err = getLidarr(req).UpdateQualityProfile(&profile)
err = getLidarr(req).UpdateQualityProfileContext(req.Context(), &profile)
if err != nil {
return http.StatusInternalServerError, fmt.Errorf("updating profile: %w", err)
}
Expand All @@ -276,7 +277,7 @@ func lidarrUpdateQualityProfile(req *http.Request) (int, interface{}) {

func lidarrRootFolders(req *http.Request) (int, interface{}) {
// Get folder list from Lidarr.
folders, err := getLidarr(req).GetRootFolders()
folders, err := getLidarr(req).GetRootFoldersContext(req.Context())
if err != nil {
return http.StatusInternalServerError, fmt.Errorf("getting folders: %w", err)
}
Expand All @@ -291,7 +292,7 @@ func lidarrRootFolders(req *http.Request) (int, interface{}) {
}

func lidarrSearchAlbum(req *http.Request) (int, interface{}) {
albums, err := getLidarr(req).GetAlbum("")
albums, err := getLidarr(req).GetAlbumContext(req.Context(), "")
if err != nil {
return http.StatusServiceUnavailable, fmt.Errorf("getting albums: %w", err)
}
Expand Down Expand Up @@ -338,7 +339,7 @@ func albumSearch(query, title string, releases []*lidarr.Release) bool {
}

func lidarrGetTags(req *http.Request) (int, interface{}) {
tags, err := getLidarr(req).GetTags()
tags, err := getLidarr(req).GetTagsContext(req.Context())
if err != nil {
return http.StatusServiceUnavailable, fmt.Errorf("getting tags: %w", err)
}
Expand All @@ -349,7 +350,7 @@ func lidarrGetTags(req *http.Request) (int, interface{}) {
func lidarrUpdateTag(req *http.Request) (int, interface{}) {
id, _ := strconv.Atoi(mux.Vars(req)["tid"])

tagID, err := getLidarr(req).UpdateTag(id, mux.Vars(req)["label"])
tagID, err := getLidarr(req).UpdateTagContext(req.Context(), id, mux.Vars(req)["label"])
if err != nil {
return http.StatusServiceUnavailable, fmt.Errorf("updating tag: %w", err)
}
Expand All @@ -358,7 +359,7 @@ func lidarrUpdateTag(req *http.Request) (int, interface{}) {
}

func lidarrSetTag(req *http.Request) (int, interface{}) {
tagID, err := getLidarr(req).AddTag(mux.Vars(req)["label"])
tagID, err := getLidarr(req).AddTagContext(req.Context(), mux.Vars(req)["label"])
if err != nil {
return http.StatusServiceUnavailable, fmt.Errorf("setting tag: %w", err)
}
Expand All @@ -374,7 +375,7 @@ func lidarrUpdateAlbum(req *http.Request) (int, interface{}) {
return http.StatusBadRequest, fmt.Errorf("decoding payload: %w", err)
}

_, err = getLidarr(req).UpdateAlbum(album.ID, &album)
_, err = getLidarr(req).UpdateAlbumContext(req.Context(), album.ID, &album)
if err != nil {
return http.StatusServiceUnavailable, fmt.Errorf("updating album: %w", err)
}
Expand All @@ -390,7 +391,7 @@ func lidarrUpdateArtist(req *http.Request) (int, interface{}) {
return http.StatusBadRequest, fmt.Errorf("decoding payload: %w", err)
}

_, err = getLidarr(req).UpdateArtist(&artist)
_, err = getLidarr(req).UpdateArtistContext(req.Context(), &artist)
if err != nil {
return http.StatusServiceUnavailable, fmt.Errorf("updating artist: %w", err)
}
Expand Down
Loading

0 comments on commit 6cae10b

Please sign in to comment.