diff options
| -rw-r--r-- | pkg/app/app.go | 19 | ||||
| -rw-r--r-- | templates/index.html | 4 |
2 files changed, 22 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") diff --git a/templates/index.html b/templates/index.html index 60b20bb..a63d4e9 100644 --- a/templates/index.html +++ b/templates/index.html @@ -11,10 +11,14 @@ <nav><a href="/">Tube</a></nav>
<main>
<div id="player">
+ {{ if $playing.ID }}
<video id="video" controls poster="/t/{{ $playing.ID}}" src="/v/{{ $playing.ID }}.mp4"></video>
<h1>{{ $playing.Title }}</h1>
<h2>{{ $playing.Modified }}</h2>
<p>{{ $playing.Description }}</p>
+ {{ else }}
+ <video id="video" controls></video>
+ {{ end }}
</div>
<div id="sidebar">
{{ range $m := .Playlist }}
|
