mirror of
https://github.com/vbatts/imgsrv.git
synced 2025-01-12 15:17:07 +00:00
adding layout for audio mime type files
This commit is contained in:
parent
f5f345859c
commit
eb1946b223
2 changed files with 21 additions and 2 deletions
14
layouts.go
14
layouts.go
|
@ -138,6 +138,18 @@ var fileViewImageTemplateHTML = `
|
|||
{{end}}
|
||||
`
|
||||
|
||||
var fileViewAudioTemplate = template.Must(template.New("file").Parse(fileViewAudioTemplateHTML))
|
||||
var fileViewAudioTemplateHTML = `
|
||||
{{if .}}
|
||||
<a href="/f/{{.Filename}}">
|
||||
<audio controls>
|
||||
<source src="/f/{{.Filename}}" type="{{.ContentType}}">
|
||||
Your browser does not support the video tag.
|
||||
</audio>
|
||||
</a>
|
||||
{{end}}
|
||||
`
|
||||
|
||||
var fileViewVideoTemplate = template.Must(template.New("file").Parse(fileViewVideoTemplateHTML))
|
||||
var fileViewVideoTemplateHTML = `
|
||||
{{if .}}
|
||||
|
@ -238,6 +250,8 @@ func ImageViewPage(w io.Writer, file types.File) (err error) {
|
|||
|
||||
if file.IsImage() {
|
||||
err = fileViewImageTemplate.Execute(w, file)
|
||||
} else if file.IsAudio() {
|
||||
err = fileViewAudioTemplate.Execute(w, file)
|
||||
} else if file.IsVideo() {
|
||||
err = fileViewVideoTemplate.Execute(w, file)
|
||||
} else {
|
||||
|
|
|
@ -29,11 +29,16 @@ func (f *File) SetContentType() {
|
|||
}
|
||||
|
||||
func (f *File) IsImage() bool {
|
||||
f.SetContentType()
|
||||
f.SetContentType()
|
||||
return strings.HasPrefix(f.ContentType, "image")
|
||||
}
|
||||
|
||||
func (f *File) IsVideo() bool {
|
||||
f.SetContentType()
|
||||
f.SetContentType()
|
||||
return strings.HasPrefix(f.ContentType, "video")
|
||||
}
|
||||
|
||||
func (f *File) IsAudio() bool {
|
||||
f.SetContentType()
|
||||
return strings.HasPrefix(f.ContentType, "audio")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue