layout: humanize some values

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
Vincent Batts 2017-04-07 14:55:13 -04:00
parent f768d2f9f6
commit b3f5e06c4d
Signed by: vbatts
GPG Key ID: 10937E57733F1362
2 changed files with 10 additions and 4 deletions

View File

@ -5,6 +5,7 @@ import (
"io"
"text/template"
humanize "github.com/dustin/go-humanize"
"github.com/vbatts/imgsrv/types"
)
@ -234,7 +235,12 @@ var fileViewTemplateHTML = `
{{end}}
`
var fileViewInfoTemplate = template.Must(template.New("file").Parse(fileViewInfoTemplateHTML))
var funcs = template.FuncMap{
"humanBytes": humanize.Bytes,
"humanTime": humanize.Time,
}
var fileViewInfoTemplate = template.Must(template.New("file").Funcs(funcs).Parse(fileViewInfoTemplateHTML))
var fileViewInfoTemplateHTML = `
{{if .}}
<br/>
@ -242,9 +248,9 @@ var fileViewInfoTemplateHTML = `
<br/>
[md5: <a href="/md5/{{.Md5}}">{{.Md5}}</a>]
<br/>
[size: {{.Length}}]
[size: {{humanBytes .Length}}]
<br/>
[UploadDate: {{.Metadata.TimeStamp}}]
[UploadDate: {{.Metadata.TimeStamp}} ({{humanTime .Metadata.TimeStamp}})]
<br/>
[<a href="/f/{{.Filename}}?delete=true">Delete</a>]
{{end}}

View File

@ -19,7 +19,7 @@ type File struct {
Md5 string
ChunkSize int
UploadDate time.Time
Length int64
Length uint64
Filename string ",omitempty"
}