Add basic video support
Additionally use filePath instead of absPath, and fileName instead of filename.
This commit is contained in:
parent
a33767656f
commit
2cf3f14477
12
display.go
12
display.go
|
@ -12,9 +12,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func fileDisplayHandler(c web.C, w http.ResponseWriter, r *http.Request) {
|
func fileDisplayHandler(c web.C, w http.ResponseWriter, r *http.Request) {
|
||||||
filename := c.URLParams["name"]
|
fileName := c.URLParams["name"]
|
||||||
absPath := path.Join(Config.filesDir, filename)
|
filePath := path.Join(Config.filesDir, fileName)
|
||||||
fileInfo, err := os.Stat(absPath)
|
fileInfo, err := os.Stat(filePath)
|
||||||
|
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
http.Error(w, http.StatusText(404), 404)
|
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()
|
defer magicmime.Close()
|
||||||
|
|
||||||
mimetype, err := magicmime.TypeByFile(absPath)
|
mimetype, err := magicmime.TypeByFile(filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
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/") {
|
if strings.HasPrefix(mimetype, "image/") {
|
||||||
tpl = pongo2.Must(pongo2.FromCache("templates/display/image.html"))
|
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 {
|
} else {
|
||||||
tpl = pongo2.Must(pongo2.FromCache("templates/display/file.html"))
|
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{
|
err = tpl.ExecuteWriter(pongo2.Context{
|
||||||
"mime": mimetype,
|
"mime": mimetype,
|
||||||
"sitename": Config.siteName,
|
"sitename": Config.siteName,
|
||||||
"filename": filename,
|
"filename": fileName,
|
||||||
"size": fileInfo.Size(),
|
"size": fileInfo.Size(),
|
||||||
}, w)
|
}, w)
|
||||||
|
|
||||||
|
|
|
@ -9,9 +9,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func fileServeHandler(c web.C, w http.ResponseWriter, r *http.Request) {
|
func fileServeHandler(c web.C, w http.ResponseWriter, r *http.Request) {
|
||||||
filename := c.URLParams["name"]
|
fileName := c.URLParams["name"]
|
||||||
absPath := path.Join(Config.filesDir, filename)
|
filePath := path.Join(Config.filesDir, fileName)
|
||||||
_, err := os.Stat(absPath)
|
_, err := os.Stat(filePath)
|
||||||
|
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
http.Error(w, http.StatusText(404), 404)
|
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
|
// plug file expiry checking here
|
||||||
|
|
||||||
http.ServeFile(w, r, absPath)
|
http.ServeFile(w, r, filePath)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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…
Reference in New Issue