feat: complete Task 3 - update web UI and handlers for Live/Remix filtering

This commit is contained in:
2026-08-05 17:19:31 +03:00
parent a3b8aa8a74
commit 0dcc86015d
4 changed files with 135 additions and 15 deletions

View File

@@ -82,6 +82,9 @@ type ArtistData struct {
Name string
MBID string
IgnoreSingles bool
IgnoreCompilations bool
IgnoreLive bool
IgnoreRemix bool
LocalAlbums []LocalAlbumView
Missing []MissingReleaseView
UIBaseURL string
@@ -146,11 +149,14 @@ func (s *Server) buildArtistData(ctx context.Context, id string) (*ArtistData, e
}
data := &ArtistData{
ID: settings.ID,
Name: settings.Name,
MBID: settings.MBID,
IgnoreSingles: settings.IgnoreSingles,
UIBaseURL: s.uiBaseURL,
ID: settings.ID,
Name: settings.Name,
MBID: settings.MBID,
IgnoreSingles: settings.IgnoreSingles,
IgnoreCompilations: settings.IgnoreCompilations,
IgnoreLive: settings.IgnoreLive,
IgnoreRemix: settings.IgnoreRemix,
UIBaseURL: s.uiBaseURL,
}
for _, a := range locals {
data.LocalAlbums = append(data.LocalAlbums, LocalAlbumView{Title: a.Title})
@@ -318,3 +324,99 @@ func (s *Server) toggleIgnoreSingles(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/artist/"+id, http.StatusSeeOther)
}
// toggleIgnoreCompilations handles POST /artist/{id}/ignore-compilations which flips the
// artist's ignore_compilations flag.
func (s *Server) toggleIgnoreCompilations(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
return
}
if !s.sameOrigin(r) {
http.Error(w, "forbidden: cross-origin request", http.StatusForbidden)
return
}
id := r.PathValue("id")
if id == "" || !isValidID(id) {
http.NotFound(w, r)
return
}
settings, err := database.GetArtistSettings(s.db, id)
if err != nil {
http.Error(w, fmt.Sprintf("load artist: %v", err), http.StatusInternalServerError)
return
}
if err := database.UpdateArtistSettings(s.db, id, map[string]interface{}{
"ignore_compilations": !settings.IgnoreCompilations,
}); err != nil {
http.Error(w, fmt.Sprintf("update artist: %v", err), http.StatusInternalServerError)
return
}
http.Redirect(w, r, "/artist/"+id, http.StatusSeeOther)
}
// toggleIgnoreLive handles POST /artist/{id}/ignore-live which flips the
// artist's ignore_live flag.
func (s *Server) toggleIgnoreLive(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
return
}
if !s.sameOrigin(r) {
http.Error(w, "forbidden: cross-origin request", http.StatusForbidden)
return
}
id := r.PathValue("id")
if id == "" || !isValidID(id) {
http.NotFound(w, r)
return
}
settings, err := database.GetArtistSettings(s.db, id)
if err != nil {
http.Error(w, fmt.Sprintf("load artist: %v", err), http.StatusInternalServerError)
return
}
if err := database.UpdateArtistSettings(s.db, id, map[string]interface{}{
"ignore_live": !settings.IgnoreLive,
}); err != nil {
http.Error(w, fmt.Sprintf("update artist: %v", err), http.StatusInternalServerError)
return
}
http.Redirect(w, r, "/artist/"+id, http.StatusSeeOther)
}
// toggleIgnoreRemix handles POST /artist/{id}/ignore-remix which flips the
// artist's ignore_remix flag.
func (s *Server) toggleIgnoreRemix(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
return
}
if !s.sameOrigin(r) {
http.Error(w, "forbidden: cross-origin request", http.StatusForbidden)
return
}
id := r.PathValue("id")
if id == "" || !isValidID(id) {
http.NotFound(w, r)
return
}
settings, err := database.GetArtistSettings(s.db, id)
if err != nil {
http.Error(w, fmt.Sprintf("load artist: %v", err), http.StatusInternalServerError)
return
}
if err := database.UpdateArtistSettings(s.db, id, map[string]interface{}{
"ignore_remix": !settings.IgnoreRemix,
}); err != nil {
http.Error(w, fmt.Sprintf("update artist: %v", err), http.StatusInternalServerError)
return
}
http.Redirect(w, r, "/artist/"+id, http.StatusSeeOther)
}