From 060b315f74f437fe36175c4ddb52379d29808d64 Mon Sep 17 00:00:00 2001 From: Thibaut Horel Date: Wed, 14 Jun 2017 00:45:42 -0400 Subject: Now Playing feature --- web.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'web.go') diff --git a/web.go b/web.go index 31a8317..371ae9f 100644 --- a/web.go +++ b/web.go @@ -7,6 +7,7 @@ import ( "io/ioutil" "log" "net/http" + "time" _ "github.com/lib/pq" ) @@ -49,11 +50,17 @@ func (app *App) root(w http.ResponseWriter, r *http.Request) { } scrobbles := app.RecentScrobbles(se.UserId) + np := app.NowPlaying(se.UserId) + np.Image = "static/np2.gif" + if time.Since(np.Time) > time.Duration(np.Duration)*time.Second { + np = nil + } app.Template.ExecuteTemplate(w, "index.tmpl", struct { - Session *UserSession - Scrobbles []*Scrobble - }{se, scrobbles}) + Session *UserSession + Scrobbles []*Scrobble + NowPlaying *Scrobble + }{se, scrobbles, np}) } func (app *App) callback(w http.ResponseWriter, r *http.Request) { -- cgit v1.2.3-70-g09d2