|
@ -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"] |
|
|
|
|
|
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) { |
|
|
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) |
|
|
|
|
|
|
|
|