2024-08-31 14:25:44 +00:00
|
|
|
package admin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
"strings"
|
|
|
|
|
2024-09-03 07:07:45 +00:00
|
|
|
"arimelody-web/global"
|
|
|
|
"arimelody-web/music/model"
|
|
|
|
"arimelody-web/music/controller"
|
2024-08-31 14:25:44 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func serveTrack() http.Handler {
|
|
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
slices := strings.Split(r.URL.Path[1:], "/")
|
|
|
|
id := slices[0]
|
2024-09-01 03:43:32 +00:00
|
|
|
track, err := music.GetTrack(global.DB, id)
|
|
|
|
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)
|
|
|
|
return
|
|
|
|
}
|
2024-08-31 14:25:44 +00:00
|
|
|
if track == nil {
|
|
|
|
http.NotFound(w, r)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-09-03 07:07:45 +00:00
|
|
|
releases, err := music.GetTrackReleases(global.DB, track.ID, true)
|
2024-09-01 03:43:32 +00:00
|
|
|
if err != nil {
|
2024-09-03 07:07:45 +00:00
|
|
|
fmt.Printf("FATAL: Failed to pull releases for %s: %s\n", id, err)
|
2024-09-01 03:43:32 +00:00
|
|
|
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
type Track struct {
|
|
|
|
*model.Track
|
2024-09-03 07:07:45 +00:00
|
|
|
Releases []*model.Release
|
2024-09-01 03:43:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = pages["track"].Execute(w, Track{ Track: track, Releases: releases })
|
2024-08-31 14:25:44 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|