Merge branch 'main' of forge

This commit is contained in:
ari melody 2024-10-20 22:27:26 +01:00
commit 96f31c19ba
Signed by: ari
GPG key ID: CF99829C92678188
6 changed files with 40 additions and 21 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

@ -25,7 +25,7 @@ func serveArtist() http.Handler {
return return
} }
credits, err := music.GetArtistCredits(global.DB, artist.ID) credits, err := music.GetArtistCredits(global.DB, artist.ID, true)
if err != nil { if err != nil {
fmt.Printf("Error rendering admin track page for %s: %s\n", id, err) fmt.Printf("Error rendering admin track page for %s: %s\n", id, err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)

View file

@ -8,7 +8,9 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
"time"
"arimelody-web/admin"
"arimelody-web/global" "arimelody-web/global"
db "arimelody-web/music/controller" db "arimelody-web/music/controller"
music "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) { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
type ( type (
creditJSON struct { creditJSON struct {
Role string `json:"role"` ID string `json:"id"`
Primary bool `json:"primary"` 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 { artistJSON struct {
*model.Artist *model.Artist
@ -46,8 +52,10 @@ func ServeArtist(artist *model.Artist) http.Handler {
} }
) )
show_hidden_releases := admin.GetSession(r) != nil
var dbCredits []*model.Credit 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 { if err != nil {
fmt.Printf("FATAL: Failed to retrieve artist credits for %s: %s\n", artist.ID, err) fmt.Printf("FATAL: Failed to retrieve artist credits for %s: %s\n", artist.ID, err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) 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{} var credits = map[string]creditJSON{}
for _, credit := range dbCredits { for _, credit := range dbCredits {
credits[credit.Release.ID] = creditJSON{ credits[credit.Release.ID] = creditJSON{
ID: credit.Release.ID,
Title: credit.Release.Title,
ReleaseDate: credit.Release.ReleaseDate,
Artwork: credit.Release.Artwork,
Role: credit.Role, Role: credit.Role,
Primary: credit.Primary, Primary: credit.Primary,
} }

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

@ -44,15 +44,15 @@ func GetArtistsNotOnRelease(db *sqlx.DB, releaseID string) ([]*model.Artist, err
return artists, nil return artists, nil
} }
func GetArtistCredits(db *sqlx.DB, artistID string) ([]*model.Credit, error) { func GetArtistCredits(db *sqlx.DB, artistID string, show_hidden bool) ([]*model.Credit, error) {
rows, err := db.Query( var query string = "SELECT release.id,release.title,release.artwork,artist.id,artist.name,artist.website,artist.avatar,role,is_primary "+
"SELECT release.id,release.title,release.artwork,artist.id,artist.name,artist.website,artist.avatar,role,is_primary "+
"FROM musiccredit "+ "FROM musiccredit "+
"JOIN musicrelease AS release ON release=release.id "+ "JOIN musicrelease AS release ON release=release.id "+
"JOIN artist ON artist=artist.id "+ "JOIN artist ON artist=artist.id "+
"WHERE artist=$1 "+ "WHERE artist=$1 "
"ORDER BY release_date DESC", if !show_hidden { query += "AND visible=true " }
artistID) query += "ORDER BY release_date DESC"
rows, err := db.Query(query, artistID)
if err != nil { if err != nil {
return nil, err return nil, err
} }

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 {