From c62df154290e737b0e0445fe5f91f45c1757bf64 Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Thu, 9 May 2013 12:36:49 -0400 Subject: [PATCH] ZOMG, just ironed out the '/v/' page, to handle embedding video with html5 tag --- layouts.go | 39 +++++++++++++++++++++++++++++++++++---- server.go | 1 - types/types.go | 18 ++++++++++++------ 3 files changed, 47 insertions(+), 11 deletions(-) diff --git a/layouts.go b/layouts.go index 16003ee..fe8b6a8 100644 --- a/layouts.go +++ b/layouts.go @@ -131,14 +131,35 @@ var listTemplateHTML = ` {{end}} ` +var fileViewImageTemplate = template.Must(template.New("file").Parse(fileViewImageTemplateHTML)) +var fileViewImageTemplateHTML = ` +{{if .}} + +{{end}} +` + +var fileViewVideoTemplate = template.Must(template.New("file").Parse(fileViewVideoTemplateHTML)) +var fileViewVideoTemplateHTML = ` +{{if .}} + + + +{{end}} +` + var fileViewTemplate = template.Must(template.New("file").Parse(fileViewTemplateHTML)) var fileViewTemplateHTML = ` {{if .}} -{{if .IsImage}} - -{{else}} {{.Filename}} {{end}} +` + +var fileViewInfoTemplate = template.Must(template.New("file").Parse(fileViewInfoTemplateHTML)) +var fileViewInfoTemplateHTML = ` +{{if .}}
[keywords:{{range $key := .Metadata.Keywords}} {{$key}}{{end}}]
@@ -211,7 +232,17 @@ func ImageViewPage(w io.Writer, file types.File) (err error) { return err } - err = fileViewTemplate.Execute(w, file) + if file.IsImage() { + err = fileViewImageTemplate.Execute(w, file) + } else if file.IsVideo() { + err = fileViewVideoTemplate.Execute(w, file) + } else { + err = fileViewTemplate.Execute(w, file) + } + if err != nil { + return err + } + err = fileViewInfoTemplate.Execute(w, file) if err != nil { return err } diff --git a/server.go b/server.go index 4f677ec..392404a 100644 --- a/server.go +++ b/server.go @@ -130,7 +130,6 @@ func routeViewsGET(w http.ResponseWriter, r *http.Request) { serverErr(w, r, err) return } - file.SetIsImage() err = ImageViewPage(w, file) if err != nil { log.Printf("error: %s", err) diff --git a/types/types.go b/types/types.go index 0b69e5d..9b8e948 100644 --- a/types/types.go +++ b/types/types.go @@ -5,7 +5,6 @@ import ( "path/filepath" "strings" "time" - "fmt" ) type Info struct { @@ -22,12 +21,19 @@ type File struct { UploadDate time.Time Length int64 Filename string ",omitempty" - IsImage bool ContentType string "contentType,omitempty" } -func (f *File) SetIsImage() { - m_type := mime.TypeByExtension(filepath.Ext(f.Filename)) - f.IsImage = strings.Contains(m_type, "image") - fmt.Println(f.Filename,f.IsImage) +func (f *File) SetContentType() { + f.ContentType = mime.TypeByExtension(filepath.Ext(f.Filename)) +} + +func (f *File) IsImage() bool { + f.SetContentType() + return strings.HasPrefix(f.ContentType, "image") +} + +func (f *File) IsVideo() bool { + f.SetContentType() + return strings.HasPrefix(f.ContentType, "video") }