1
0
Fork 0
mirror of https://github.com/vbatts/imgsrv.git synced 2024-11-23 16:45:39 +00:00

ZOMG, just ironed out the '/v/' page, to handle embedding video with

html5 tag
This commit is contained in:
Vincent Batts 2013-05-09 12:36:49 -04:00
parent 967daf48b2
commit c62df15429
3 changed files with 47 additions and 11 deletions

View file

@ -131,14 +131,35 @@ var listTemplateHTML = `
{{end}}
`
var fileViewImageTemplate = template.Must(template.New("file").Parse(fileViewImageTemplateHTML))
var fileViewImageTemplateHTML = `
{{if .}}
<a href="/f/{{.Filename}}"><img src="/f/{{.Filename}}"></a>
{{end}}
`
var fileViewVideoTemplate = template.Must(template.New("file").Parse(fileViewVideoTemplateHTML))
var fileViewVideoTemplateHTML = `
{{if .}}
<a href="/f/{{.Filename}}">
<video width="320" height="240" controls>
<source src="/f/{{.Filename}}" type="{{.ContentType}}">
Your browser does not support the video tag.
</video>
</a>
{{end}}
`
var fileViewTemplate = template.Must(template.New("file").Parse(fileViewTemplateHTML))
var fileViewTemplateHTML = `
{{if .}}
{{if .IsImage}}
<a href="/f/{{.Filename}}"><img src="/f/{{.Filename}}"></a>
{{else}}
<a href="/f/{{.Filename}}">{{.Filename}}</a>
{{end}}
`
var fileViewInfoTemplate = template.Must(template.New("file").Parse(fileViewInfoTemplateHTML))
var fileViewInfoTemplateHTML = `
{{if .}}
<br/>
[keywords:{{range $key := .Metadata.Keywords}} <a href="/k/{{$key}}">{{$key}}</a>{{end}}]
<br/>
@ -211,7 +232,17 @@ func ImageViewPage(w io.Writer, file types.File) (err error) {
return err
}
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
}

View file

@ -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)

View file

@ -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")
}