summaryrefslogtreecommitdiff
path: root/pkg/app
diff options
context:
space:
mode:
authordavy <davy.wybiral@gmail.com>2019-06-28 17:51:38 -0500
committerdavy <davy.wybiral@gmail.com>2019-06-28 17:51:38 -0500
commit6e9f1ca8ab34914bcc2327e7d4fab99e6ff6e73c (patch)
tree57c8cd835fc0b5ef07cb4fc558dfcc2bf56c79b3 /pkg/app
parentb46830c8806fc1293bc8cfdf5496cd024fcde6c4 (diff)
handle empty playlist
Diffstat (limited to 'pkg/app')
-rw-r--r--pkg/app/app.go19
1 files changed, 18 insertions, 1 deletions
diff --git a/pkg/app/app.go b/pkg/app/app.go
index 1cf147e..61d93c2 100644
--- a/pkg/app/app.go
+++ b/pkg/app/app.go
@@ -88,7 +88,17 @@ func (a *App) watch() {
func (a *App) indexHandler(w http.ResponseWriter, r *http.Request) {
log.Printf("/")
pl := a.Library.Playlist()
- http.Redirect(w, r, "/"+pl[0].ID, 302)
+ if len(pl) > 0 {
+ http.Redirect(w, r, "/"+pl[0].ID, 302)
+ } else {
+ a.Templates.ExecuteTemplate(w, "index.html", &struct {
+ Playing *media.Video
+ Playlist media.Playlist
+ }{
+ Playing: &media.Video{ID: ""},
+ Playlist: a.Library.Playlist(),
+ })
+ }
}
func (a *App) pageHandler(w http.ResponseWriter, r *http.Request) {
@@ -97,6 +107,13 @@ func (a *App) pageHandler(w http.ResponseWriter, r *http.Request) {
log.Printf("/%s", id)
playing, ok := a.Library.Videos[id]
if !ok {
+ a.Templates.ExecuteTemplate(w, "index.html", &struct {
+ Playing *media.Video
+ Playlist media.Playlist
+ }{
+ Playing: &media.Video{ID: ""},
+ Playlist: a.Library.Playlist(),
+ })
return
}
w.Header().Set("Content-Type", "text/html; charset=utf-8")