diff --git a/.air.toml b/.air.toml index ea2b4d5..f8a1acf 100644 --- a/.air.toml +++ b/.air.toml @@ -7,7 +7,7 @@ tmp_dir = "tmp" bin = "./tmp/main" cmd = "go build -o ./tmp/main ." delay = 1000 - exclude_dir = ["admin\\static", "public", "uploads", "test"] + exclude_dir = ["admin/static", "public", "uploads", "test", "db"] exclude_file = [] exclude_regex = ["_test.go"] exclude_unchanged = false diff --git a/admin/artisthttp.go b/admin/artisthttp.go index 31a7c9c..4f66798 100644 --- a/admin/artisthttp.go +++ b/admin/artisthttp.go @@ -25,7 +25,7 @@ func serveArtist() http.Handler { return } - credits, err := music.GetArtistCredits(global.DB, artist.ID) + credits, err := music.GetArtistCredits(global.DB, artist.ID, true) if err != nil { fmt.Printf("Error rendering admin track page for %s: %s\n", id, err) http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) diff --git a/api/artist.go b/api/artist.go index 2d5f5e6..90bd18a 100644 --- a/api/artist.go +++ b/api/artist.go @@ -8,7 +8,9 @@ import ( "os" "path/filepath" "strings" + "time" + "arimelody-web/admin" "arimelody-web/global" db "arimelody-web/music/controller" music "arimelody-web/music/controller" @@ -37,8 +39,12 @@ func ServeArtist(artist *model.Artist) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { type ( creditJSON struct { - Role string `json:"role"` - Primary bool `json:"primary"` + ID string `json:"id"` + Title string `json:"title"` + ReleaseDate time.Time `json:"releaseDate" db:"release_date"` + Artwork string `json:"artwork"` + Role string `json:"role"` + Primary bool `json:"primary"` } artistJSON struct { *model.Artist @@ -46,8 +52,10 @@ func ServeArtist(artist *model.Artist) http.Handler { } ) + show_hidden_releases := admin.GetSession(r) != nil + var dbCredits []*model.Credit - dbCredits, err := db.GetArtistCredits(global.DB, artist.ID) + dbCredits, err := db.GetArtistCredits(global.DB, artist.ID, show_hidden_releases) if err != nil { fmt.Printf("FATAL: Failed to retrieve artist credits for %s: %s\n", artist.ID, err) http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) @@ -57,6 +65,10 @@ func ServeArtist(artist *model.Artist) http.Handler { var credits = map[string]creditJSON{} for _, credit := range dbCredits { credits[credit.Release.ID] = creditJSON{ + ID: credit.Release.ID, + Title: credit.Release.Title, + ReleaseDate: credit.Release.ReleaseDate, + Artwork: credit.Release.Artwork, Role: credit.Role, Primary: credit.Primary, } diff --git a/api/release.go b/api/release.go index 763383f..3027a8c 100644 --- a/api/release.go +++ b/api/release.go @@ -27,6 +27,7 @@ func ServeCatalog() http.Handler { type Release struct { ID string `json:"id"` Title string `json:"title"` + Artists []string `json:"artists"` ReleaseType model.ReleaseType `json:"type" db:"type"` ReleaseDate time.Time `json:"releaseDate" db:"release_date"` Artwork string `json:"artwork"` @@ -40,9 +41,15 @@ func ServeCatalog() http.Handler { if !release.Visible && !authorised { continue } + artists := []string{} + for _, credit := range release.Credits { + if !credit.Primary { continue } + artists = append(artists, credit.Artist.Name) + } catalog = append(catalog, Release{ ID: release.ID, Title: release.Title, + Artists: artists, ReleaseType: release.ReleaseType, ReleaseDate: release.ReleaseDate, Artwork: release.Artwork, diff --git a/music/controller/artist.go b/music/controller/artist.go index 2ae92e7..10824a8 100644 --- a/music/controller/artist.go +++ b/music/controller/artist.go @@ -44,15 +44,15 @@ func GetArtistsNotOnRelease(db *sqlx.DB, releaseID string) ([]*model.Artist, err return artists, nil } -func GetArtistCredits(db *sqlx.DB, artistID string) ([]*model.Credit, error) { - rows, err := db.Query( - "SELECT release.id,release.title,release.artwork,artist.id,artist.name,artist.website,artist.avatar,role,is_primary "+ +func GetArtistCredits(db *sqlx.DB, artistID string, show_hidden bool) ([]*model.Credit, error) { + var query string = "SELECT release.id,title,artwork,release_date,artist.id,name,website,avatar,role,is_primary "+ "FROM musiccredit "+ "JOIN musicrelease AS release ON release=release.id "+ "JOIN artist ON artist=artist.id "+ - "WHERE artist=$1 "+ - "ORDER BY release_date DESC", - artistID) + "WHERE artist=$1 " + if !show_hidden { query += "AND visible=true " } + query += "ORDER BY release_date DESC" + rows, err := db.Query(query, artistID) if err != nil { return nil, err } @@ -69,6 +69,7 @@ func GetArtistCredits(db *sqlx.DB, artistID string) ([]*model.Credit, error) { &credit.Release.ID, &credit.Release.Title, &credit.Release.Artwork, + &credit.Release.ReleaseDate, &credit.Artist.ID, &credit.Artist.Name, &credit.Artist.Website, diff --git a/music/controller/release.go b/music/controller/release.go index 4bd2cd6..2aeb236 100644 --- a/music/controller/release.go +++ b/music/controller/release.go @@ -66,17 +66,17 @@ func GetAllReleases(db *sqlx.DB, onlyVisible bool, limit int, full bool) ([]*mod return nil, err } - if full { - for _, release := range releases { - // get credits - credits, err := GetReleaseCredits(db, release.ID) - if err != nil { - return nil, errors.New(fmt.Sprintf("Credits: %s", err)) - } - for _, credit := range credits { - release.Credits = append(release.Credits, credit) - } + for _, release := range releases { + // get credits + credits, err := GetReleaseCredits(db, release.ID) + if err != nil { + return nil, errors.New(fmt.Sprintf("Credits: %s", err)) + } + for _, credit := range credits { + release.Credits = append(release.Credits, credit) + } + if full { // get tracks tracks, err := GetReleaseTracks(db, release.ID) if err != nil {