handle empty playlist
This commit is contained in:
parent
b46830c880
commit
6e9f1ca8ab
2 changed files with 22 additions and 1 deletions
|
@ -88,7 +88,17 @@ func (a *App) watch() {
|
||||||
func (a *App) indexHandler(w http.ResponseWriter, r *http.Request) {
|
func (a *App) indexHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
log.Printf("/")
|
log.Printf("/")
|
||||||
pl := a.Library.Playlist()
|
pl := a.Library.Playlist()
|
||||||
|
if len(pl) > 0 {
|
||||||
http.Redirect(w, r, "/"+pl[0].ID, 302)
|
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) {
|
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)
|
log.Printf("/%s", id)
|
||||||
playing, ok := a.Library.Videos[id]
|
playing, ok := a.Library.Videos[id]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
a.Templates.ExecuteTemplate(w, "index.html", &struct {
|
||||||
|
Playing *media.Video
|
||||||
|
Playlist media.Playlist
|
||||||
|
}{
|
||||||
|
Playing: &media.Video{ID: ""},
|
||||||
|
Playlist: a.Library.Playlist(),
|
||||||
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||||
|
|
|
@ -11,10 +11,14 @@
|
||||||
<nav><a href="/">Tube</a></nav>
|
<nav><a href="/">Tube</a></nav>
|
||||||
<main>
|
<main>
|
||||||
<div id="player">
|
<div id="player">
|
||||||
|
{{ if $playing.ID }}
|
||||||
<video id="video" controls poster="/t/{{ $playing.ID}}" src="/v/{{ $playing.ID }}.mp4"></video>
|
<video id="video" controls poster="/t/{{ $playing.ID}}" src="/v/{{ $playing.ID }}.mp4"></video>
|
||||||
<h1>{{ $playing.Title }}</h1>
|
<h1>{{ $playing.Title }}</h1>
|
||||||
<h2>{{ $playing.Modified }}</h2>
|
<h2>{{ $playing.Modified }}</h2>
|
||||||
<p>{{ $playing.Description }}</p>
|
<p>{{ $playing.Description }}</p>
|
||||||
|
{{ else }}
|
||||||
|
<video id="video" controls></video>
|
||||||
|
{{ end }}
|
||||||
</div>
|
</div>
|
||||||
<div id="sidebar">
|
<div id="sidebar">
|
||||||
{{ range $m := .Playlist }}
|
{{ range $m := .Playlist }}
|
||||||
|
|
Loading…
Reference in a new issue