1
0

Now Index page will be shown even if Icecast status cannot be retrieved.

This commit is contained in:
Alexander Andreev 2022-05-24 18:26:59 +04:00
parent 630c703c12
commit 3ec15fbd2a
Signed by: Arav
GPG Key ID: 0388CC8FAA51063F

View File

@ -62,16 +62,7 @@ func (h *RadioHandlers) Index(w http.ResponseWriter, r *http.Request) {
status, err := radio.IcecastGetStatus(h.conf.Icecast.URL) status, err := radio.IcecastGetStatus(h.conf.Icecast.URL)
if err != nil { if err != nil {
h.logErr.Println("failed to get Icecast status:", err) h.logErr.Println("failed to get Icecast status:", err)
status = &radio.IcecastStatus{} } else {
return
}
songs, err := radio.IcecastLastPlayedSongs(h.conf.ListLastNSongs,
h.conf.Icecast.Playlist)
if err != nil {
h.logErr.Println("cannot retrieve last songs:", err)
}
if tim, err := time.Parse(time.RFC1123Z, status.ServerStartDate); err == nil { if tim, err := time.Parse(time.RFC1123Z, status.ServerStartDate); err == nil {
status.ServerStartDate = utils.ToClientTimezone(tim, r).Format(time.RFC1123) status.ServerStartDate = utils.ToClientTimezone(tim, r).Format(time.RFC1123)
} }
@ -79,14 +70,21 @@ func (h *RadioHandlers) Index(w http.ResponseWriter, r *http.Request) {
if tim, err := time.Parse(FormatISO8601, status.ServerStartISO8601); err == nil { if tim, err := time.Parse(FormatISO8601, status.ServerStartISO8601); err == nil {
status.ServerStartISO8601 = utils.ToClientTimezone(tim, r).Format(FormatISO8601) status.ServerStartISO8601 = utils.ToClientTimezone(tim, r).Format(FormatISO8601)
} }
}
songs, err := radio.IcecastLastPlayedSongs(h.conf.ListLastNSongs,
h.conf.Icecast.Playlist)
if err != nil {
h.logErr.Println("cannot retrieve last songs:", err)
} else {
for i := 0; i < len(songs); i++ { for i := 0; i < len(songs); i++ {
if tim, err := time.Parse(radio.SongTimeFormat, songs[i].Time); err == nil { if tim, err := time.Parse(radio.SongTimeFormat, songs[i].Time); err == nil {
songs[i].Time = utils.ToClientTimezone(tim, r).Format("15:04") songs[i].Time = utils.ToClientTimezone(tim, r).Format("15:04")
} }
} }
}
if err := compiledTemplates["index"].Execute(w, &IndexData{ if err := web.Template("index").Execute(w, &IndexData{
MainSite: utils.MainSite(r.Host), MainSite: utils.MainSite(r.Host),
Status: status, Status: status,
Songs: songs, Songs: songs,