|
@ -6,8 +6,8 @@ import ( |
|
|
"path" |
|
|
"path" |
|
|
"strings" |
|
|
"strings" |
|
|
|
|
|
|
|
|
|
|
|
"bitbucket.org/taruti/mimemagic" |
|
|
"github.com/flosch/pongo2" |
|
|
"github.com/flosch/pongo2" |
|
|
"github.com/rakyll/magicmime" |
|
|
|
|
|
"github.com/zenazn/goji/web" |
|
|
"github.com/zenazn/goji/web" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
@ -21,17 +21,12 @@ func fileDisplayHandler(c web.C, w http.ResponseWriter, r *http.Request) { |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if err := magicmime.Open(magicmime.MAGIC_MIME_TYPE | |
|
|
|
|
|
magicmime.MAGIC_SYMLINK | |
|
|
|
|
|
magicmime.MAGIC_ERROR); err != nil { |
|
|
|
|
|
oopsHandler(c, w, r) |
|
|
|
|
|
} |
|
|
|
|
|
defer magicmime.Close() |
|
|
|
|
|
|
|
|
file, _ := os.Open(filePath) |
|
|
|
|
|
header := make([]byte, 512) |
|
|
|
|
|
file.Read(header) |
|
|
|
|
|
file.Close() |
|
|
|
|
|
|
|
|
mimetype, err := magicmime.TypeByFile(filePath) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
oopsHandler(c, w, r) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
mimetype := mimemagic.Match("", header) |
|
|
|
|
|
|
|
|
var tpl *pongo2.Template |
|
|
var tpl *pongo2.Template |
|
|
|
|
|
|
|
|