add artists list to /api/v1/music

This commit is contained in:
ari melody 2024-09-12 09:46:40 +01:00
parent bc1b6c5872
commit e69cf78e57
Signed by: ari
GPG key ID: CF99829C92678188
3 changed files with 18 additions and 11 deletions

View file

@ -7,7 +7,7 @@ tmp_dir = "tmp"
bin = "./tmp/main" bin = "./tmp/main"
cmd = "go build -o ./tmp/main ." cmd = "go build -o ./tmp/main ."
delay = 1000 delay = 1000
exclude_dir = ["admin\\static", "public", "uploads", "test"] exclude_dir = ["admin/static", "public", "uploads", "test", "db"]
exclude_file = [] exclude_file = []
exclude_regex = ["_test.go"] exclude_regex = ["_test.go"]
exclude_unchanged = false exclude_unchanged = false

View file

@ -27,6 +27,7 @@ func ServeCatalog() http.Handler {
type Release struct { type Release struct {
ID string `json:"id"` ID string `json:"id"`
Title string `json:"title"` Title string `json:"title"`
Artists []string `json:"artists"`
ReleaseType model.ReleaseType `json:"type" db:"type"` ReleaseType model.ReleaseType `json:"type" db:"type"`
ReleaseDate time.Time `json:"releaseDate" db:"release_date"` ReleaseDate time.Time `json:"releaseDate" db:"release_date"`
Artwork string `json:"artwork"` Artwork string `json:"artwork"`
@ -40,9 +41,15 @@ func ServeCatalog() http.Handler {
if !release.Visible && !authorised { if !release.Visible && !authorised {
continue continue
} }
artists := []string{}
for _, credit := range release.Credits {
if !credit.Primary { continue }
artists = append(artists, credit.Artist.Name)
}
catalog = append(catalog, Release{ catalog = append(catalog, Release{
ID: release.ID, ID: release.ID,
Title: release.Title, Title: release.Title,
Artists: artists,
ReleaseType: release.ReleaseType, ReleaseType: release.ReleaseType,
ReleaseDate: release.ReleaseDate, ReleaseDate: release.ReleaseDate,
Artwork: release.Artwork, Artwork: release.Artwork,

View file

@ -66,17 +66,17 @@ func GetAllReleases(db *sqlx.DB, onlyVisible bool, limit int, full bool) ([]*mod
return nil, err return nil, err
} }
if full { for _, release := range releases {
for _, release := range releases { // get credits
// get credits credits, err := GetReleaseCredits(db, release.ID)
credits, err := GetReleaseCredits(db, release.ID) if err != nil {
if err != nil { return nil, errors.New(fmt.Sprintf("Credits: %s", err))
return nil, errors.New(fmt.Sprintf("Credits: %s", err)) }
} for _, credit := range credits {
for _, credit := range credits { release.Credits = append(release.Credits, credit)
release.Credits = append(release.Credits, credit) }
}
if full {
// get tracks // get tracks
tracks, err := GetReleaseTracks(db, release.ID) tracks, err := GetReleaseTracks(db, release.ID)
if err != nil { if err != nil {