1
0

In Status handler: added missing Content-Type; Added most listened song; Removed with-list query, just return everything; Added http.Error().

This commit is contained in:
Alexander Andreev 2023-10-02 02:22:14 +04:00
parent 1b38c5d86c
commit 8322d2a7a8
Signed by: Arav
GPG Key ID: D22A817D95815393

View File

@ -94,18 +94,21 @@ func (dj *DJHandlers) Songs(w http.ResponseWriter, r *http.Request) {
}
func (dj *DJHandlers) Status(w http.ResponseWriter, r *http.Request) {
withList := r.URL.Query().Has("with-list")
if withList {
w.Header().Add("Content-Type", "application/json")
err := json.NewEncoder(w).Encode(&struct {
Current *radio.Song_ `json:"current_song,omitempty"`
Listeners *radio.ListenerCounter `json:"listeners"`
List []radio.Song_ `json:"last_songs,omitempty"`
Mls *radio.MostListenedSong `json:"most_listened_song,omitempty"`
}{
Current: songList.Current(),
Listeners: dj.listeners,
List: songList.List()})
List: songList.List(),
Mls: radio.MostListened()})
if err != nil {
log.Println("DJHandlers.Status-withList:", err)
log.Println("DJHandlers.Status:", err)
http.Error(w, "status parsing failed", http.StatusInternalServerError)
}
}
}
}