update track API and lyrics fixes

Signed-off-by: ari melody <ari@arimelody.me>
This commit is contained in:
ari melody 2024-08-04 00:23:55 +01:00
parent 05e16a0867
commit f276ef1ff2
5 changed files with 60 additions and 15 deletions

View file

@ -33,23 +33,32 @@ func Handler() http.Handler {
return return
} }
type IndexData struct { type (
Releases []*musicModel.Release Track struct {
Artists []*musicModel.Artist *musicModel.Track
Tracks []*musicModel.Track Lyrics template.HTML
} // Number int
var orphan_tracks = []*musicModel.Track{}
for _, track := range global.Tracks {
if track.Release == nil {
orphan_tracks = append(orphan_tracks, track)
} }
IndexData struct {
Releases []*musicModel.Release
Artists []*musicModel.Artist
Tracks []Track
}
)
var tracks = []Track{}
for _, track := range global.Tracks {
tracks = append(tracks, Track{
Track: track,
Lyrics: template.HTML(strings.Replace(track.Lyrics, "\n", "<br>", -1)),
})
} }
serveTemplate("index.html", IndexData{ serveTemplate("index.html", IndexData{
Releases: global.Releases, Releases: global.Releases,
Artists: global.Artists, Artists: global.Artists,
Tracks: global.Tracks, Tracks: tracks,
}).ServeHTTP(w, r) }).ServeHTTP(w, r)
})) }))

View file

@ -226,13 +226,39 @@ a:hover {
} }
h2.track-title { h2.track-title {
margin: 0 margin: 0;
display: flex;
flex-direction: row;
justify-content: space-between;
}
.track-album {
margin-left: auto;
font-style: italic;
font-size: .75em;
opacity: .5;
}
.track-album.empty {
color: #ff2020;
opacity: 1;
} }
.track-description { .track-description {
font-style: italic; font-style: italic;
} }
.track-lyrics {
max-height: 10em;
overflow-y: scroll;
}
.track .empty { .track .empty {
opacity: 0.75; opacity: 0.75;
} }
@media screen and (max-width: 520px) {
body {
font-size: 12px;
}
}

View file

@ -55,8 +55,7 @@ func UpdateTrackDB(db *sqlx.DB, track *model.Track) error {
_, err := db.Exec( _, err := db.Exec(
"UPDATE musictrack "+ "UPDATE musictrack "+
"SET title=$2, description=$3, lyrics=$4, preview_url=$5 "+ "SET title=$2, description=$3, lyrics=$4, preview_url=$5 "+
"WHERE id=$1"+ "WHERE id=$1",
"RETURNING id",
track.ID, track.ID,
track.Title, track.Title,
track.Description, track.Description,

View file

@ -3,7 +3,9 @@ package view
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"html/template"
"net/http" "net/http"
"strings"
"arimelody.me/arimelody.me/admin" "arimelody.me/arimelody.me/admin"
"arimelody.me/arimelody.me/global" "arimelody.me/arimelody.me/global"
@ -52,6 +54,7 @@ func ServeGateway() http.Handler {
type ( type (
GatewayTrack struct { GatewayTrack struct {
*model.Track *model.Track
Lyrics template.HTML
Number int Number int
} }
@ -72,6 +75,7 @@ func ServeGateway() http.Handler {
for i, track := range release.Tracks { for i, track := range release.Tracks {
tracks = append([]GatewayTrack{GatewayTrack{ tracks = append([]GatewayTrack{GatewayTrack{
Track: track, Track: track,
Lyrics: template.HTML(strings.Replace(track.Lyrics, "\n", "<br>", -1)),
Number: len(release.Tracks) - i, Number: len(release.Tracks) - i,
}}, tracks...) }}, tracks...)
} }

View file

@ -62,7 +62,14 @@
<div class="card tracks"> <div class="card tracks">
{{range $Track := .Tracks}} {{range $Track := .Tracks}}
<div class="track"> <div class="track">
<h2 class="track-title">{{$Track.Title}}</h2> <h2 class="track-title">
{{$Track.Title}}
{{if $Track.Release}}
<small class="track-album">{{$Track.Release.Title}}</small>
{{else}}
<small class="track-album empty">(no album)</small>
{{end}}
</h2>
{{if $Track.Description}} {{if $Track.Description}}
<p class="track-description">{{$Track.Description}}</p> <p class="track-description">{{$Track.Description}}</p>
{{else}} {{else}}