Merge branch 'main' of forge
This commit is contained in:
commit
96f31c19ba
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,release.title,release.artwork,artist.id,artist.name,artist.website,artist.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
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue