Display video size

This commit is contained in:
James Mills 2020-03-27 18:16:23 +10:00
parent 10a5f82498
commit 89d7d71cc5
No known key found for this signature in database
GPG key ID: AC4C014F1440EBD6
4 changed files with 99 additions and 94 deletions

View file

@ -15,6 +15,7 @@ import (
"strings" "strings"
rice "github.com/GeertJohan/go.rice" rice "github.com/GeertJohan/go.rice"
"github.com/dustin/go-humanize"
"github.com/fsnotify/fsnotify" "github.com/fsnotify/fsnotify"
"github.com/gorilla/handlers" "github.com/gorilla/handlers"
"github.com/gorilla/mux" "github.com/gorilla/mux"
@ -74,17 +75,21 @@ func NewApp(cfg *Config) (*App, error) {
a.Templates = newTemplateStore("base") a.Templates = newTemplateStore("base")
indexTemplate := template.New("index") templateFuncs := map[string]interface{}{
"bytes": func(size int64) string { return humanize.Bytes(uint64(size)) },
}
indexTemplate := template.New("index").Funcs(templateFuncs)
template.Must(indexTemplate.Parse(box.MustString("index.html"))) template.Must(indexTemplate.Parse(box.MustString("index.html")))
template.Must(indexTemplate.Parse(box.MustString("base.html"))) template.Must(indexTemplate.Parse(box.MustString("base.html")))
a.Templates.Add("index", indexTemplate) a.Templates.Add("index", indexTemplate)
uploadTemplate := template.New("upload") uploadTemplate := template.New("upload").Funcs(templateFuncs)
template.Must(uploadTemplate.Parse(box.MustString("upload.html"))) template.Must(uploadTemplate.Parse(box.MustString("upload.html")))
template.Must(uploadTemplate.Parse(box.MustString("base.html"))) template.Must(uploadTemplate.Parse(box.MustString("base.html")))
a.Templates.Add("upload", uploadTemplate) a.Templates.Add("upload", uploadTemplate)
importTemplate := template.New("import") importTemplate := template.New("import").Funcs(templateFuncs)
template.Must(importTemplate.Parse(box.MustString("import.html"))) template.Must(importTemplate.Parse(box.MustString("import.html")))
template.Must(importTemplate.Parse(box.MustString("base.html"))) template.Must(importTemplate.Parse(box.MustString("base.html")))
a.Templates.Add("import", importTemplate) a.Templates.Add("import", importTemplate)

File diff suppressed because one or more lines are too long

2
go.mod
View file

@ -9,7 +9,7 @@ require (
github.com/dhowden/tag v0.0.0-20190519100835-db0c67e351b1 github.com/dhowden/tag v0.0.0-20190519100835-db0c67e351b1
github.com/disintegration/gift v1.2.1 // indirect github.com/disintegration/gift v1.2.1 // indirect
github.com/disintegration/imaging v1.6.2 // indirect github.com/disintegration/imaging v1.6.2 // indirect
github.com/dustin/go-humanize v1.0.0 // indirect github.com/dustin/go-humanize v1.0.0
github.com/fsnotify/fsnotify v1.4.7 github.com/fsnotify/fsnotify v1.4.7
github.com/gorilla/feeds v1.1.1 github.com/gorilla/feeds v1.1.1
github.com/gorilla/handlers v1.4.2 github.com/gorilla/handlers v1.4.2

View file

@ -4,7 +4,7 @@
{{ if $playing.ID }} {{ 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.Views }} views • {{ $playing.Modified }}</h2> <h2>{{ $playing.Views }} views • {{ $playing.Modified }}<br />{{ $playing.Size | bytes }}</h2>
<p>{{ $playing.Description }}</p> <p>{{ $playing.Description }}</p>
{{ else }} {{ else }}
<video id="video" controls></video> <video id="video" controls></video>
@ -26,7 +26,7 @@
<img src="/t/{{ $m.ID }}"> <img src="/t/{{ $m.ID }}">
<div> <div>
<h1>{{ $m.Title }}</h1> <h1>{{ $m.Title }}</h1>
<h2>{{ $m.Views }} views • {{ $m.Modified }}</h2> <h2>{{ $m.Views }} views • {{ $m.Modified }}<br />{{ $m.Size | bytes }}</h2>
</div> </div>
</a> </a>
{{ end }} {{ end }}