From e9474ba0b68a996a707ed928e115510ff60cabb8 Mon Sep 17 00:00:00 2001 From: Daniel Mason Date: Sun, 28 Mar 2021 22:24:18 +1300 Subject: [PATCH] Add proper handling to album links --- internal/goscrobble/album.go | 14 ++++++++++---- internal/goscrobble/server.go | 10 +++++----- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/internal/goscrobble/album.go b/internal/goscrobble/album.go index 2618549a..e77d3b80 100644 --- a/internal/goscrobble/album.go +++ b/internal/goscrobble/album.go @@ -28,7 +28,10 @@ func insertAlbum(name string, mbid string, artists []string, tx *sql.Tx) (Album, } album = fetchAlbum("mbid", mbid, tx) - album.linkAlbumToArtists(artists, tx) + err = album.linkAlbumToArtists(artists, tx) + if err != nil { + return album, err + } } } else { album = fetchAlbum("name", name, tx) @@ -40,7 +43,10 @@ func insertAlbum(name string, mbid string, artists []string, tx *sql.Tx) (Album, } album = fetchAlbum("name", name, tx) - album.linkAlbumToArtists(artists, tx) + err = album.linkAlbumToArtists(artists, tx) + if err != nil { + return album, err + } } } @@ -76,8 +82,8 @@ func insertNewAlbum(name string, mbid string, tx *sql.Tx) error { func (album *Album) linkAlbumToArtists(artists []string, tx *sql.Tx) error { var err error for _, artist := range artists { - _, err = tx.Exec("INSERT INTO `track_artist` (`track`, `artist`) "+ - "VALUES (UUID_TO_BIN(?, true), UUID_TO_BIN(?, true)", album.Uuid, artist) + _, err = tx.Exec("INSERT INTO `album_artist` (`album`, `artist`) "+ + "VALUES (UUID_TO_BIN(?, true), UUID_TO_BIN(?, true))", album.Uuid, artist) if err != nil { return err } diff --git a/internal/goscrobble/server.go b/internal/goscrobble/server.go index 5627f912..5e08cdd1 100644 --- a/internal/goscrobble/server.go +++ b/internal/goscrobble/server.go @@ -97,10 +97,10 @@ func throwBadReq(w http.ResponseWriter, m string) { http.Error(w, err.Error(), http.StatusBadRequest) } -// throwUnauthorized - Throws a 403 +// throwOkMessage - Throws a happy 200 func throwOkMessage(w http.ResponseWriter, m string) { jr := jsonResponse{ - Err: m, + Msg: m, } js, _ := json.Marshal(&jr) err := errors.New(string(js)) @@ -241,11 +241,11 @@ func handleIngress(w http.ResponseWriter, r *http.Request) { return } - throwOkMessage(w, "{}") + throwOkMessage(w, "success") return } - // Lets trick 'em for now ;) ;) - fmt.Fprintf(w, "{}") + + throwBadReq(w, "Unknown ingress type") } // FRONTEND HANDLING