Browse Source

Merge branch 'Uncurlhalo-video-display-handler'

pull/4/head
andreimarcu 9 years ago
parent
commit
8fa85eb603
  1. 3
      .gitignore
  2. 12
      display.go
  3. 8
      fileserve.go
  4. 10
      templates/display/video.html

3
.gitignore

@ -7,6 +7,9 @@
_obj
_test
# Swap files
*.swp
# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out

12
display.go

@ -12,9 +12,9 @@ import (
)
func fileDisplayHandler(c web.C, w http.ResponseWriter, r *http.Request) {
filename := c.URLParams["name"]
absPath := path.Join(Config.filesDir, filename)
fileInfo, err := os.Stat(absPath)
fileName := c.URLParams["name"]
filePath := path.Join(Config.filesDir, fileName)
fileInfo, err := os.Stat(filePath)
if os.IsNotExist(err) {
http.Error(w, http.StatusText(404), 404)
@ -28,7 +28,7 @@ func fileDisplayHandler(c web.C, w http.ResponseWriter, r *http.Request) {
}
defer magicmime.Close()
mimetype, err := magicmime.TypeByFile(absPath)
mimetype, err := magicmime.TypeByFile(filePath)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
@ -37,6 +37,8 @@ func fileDisplayHandler(c web.C, w http.ResponseWriter, r *http.Request) {
if strings.HasPrefix(mimetype, "image/") {
tpl = pongo2.Must(pongo2.FromCache("templates/display/image.html"))
} else if strings.HasPrefix(mimetype, "video/") {
tpl = pongo2.Must(pongo2.FromCache("templates/display/video.html"))
} else {
tpl = pongo2.Must(pongo2.FromCache("templates/display/file.html"))
}
@ -44,7 +46,7 @@ func fileDisplayHandler(c web.C, w http.ResponseWriter, r *http.Request) {
err = tpl.ExecuteWriter(pongo2.Context{
"mime": mimetype,
"sitename": Config.siteName,
"filename": filename,
"filename": fileName,
"size": fileInfo.Size(),
}, w)

8
fileserve.go

@ -9,9 +9,9 @@ import (
)
func fileServeHandler(c web.C, w http.ResponseWriter, r *http.Request) {
filename := c.URLParams["name"]
absPath := path.Join(Config.filesDir, filename)
_, err := os.Stat(absPath)
fileName := c.URLParams["name"]
filePath := path.Join(Config.filesDir, fileName)
_, err := os.Stat(filePath)
if os.IsNotExist(err) {
http.Error(w, http.StatusText(404), 404)
@ -20,5 +20,5 @@ func fileServeHandler(c web.C, w http.ResponseWriter, r *http.Request) {
// plug file expiry checking here
http.ServeFile(w, r, absPath)
http.ServeFile(w, r, filePath)
}

10
templates/display/video.html

@ -0,0 +1,10 @@
{% extends "base.html" %}
{% block main %}
<div id='video'>
<video controls autoplay width="800">
<source src="/selif/{{ filename }}"/>
</video>
</div>
{% endblock %}
Loading…
Cancel
Save