diff --git a/.gitignore b/.gitignore index daf913b..e294ae3 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,9 @@ _obj _test +# Swap files +*.swp + # Architecture specific extensions/prefixes *.[568vq] [568vq].out diff --git a/display.go b/display.go index 4e236f9..664c3be 100644 --- a/display.go +++ b/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) diff --git a/fileserve.go b/fileserve.go index 7127963..b34020c 100644 --- a/fileserve.go +++ b/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) } diff --git a/templates/display/video.html b/templates/display/video.html new file mode 100644 index 0000000..0bf5486 --- /dev/null +++ b/templates/display/video.html @@ -0,0 +1,10 @@ +{% extends "base.html" %} + +{% block main %} +
+ +
+ +{% endblock %}