thumbnailer: option to set custom mime type for file decoding

This commit is contained in:
mappu 2017-11-18 12:52:17 +13:00
parent 060cefe642
commit 3905686363

View File

@ -92,18 +92,18 @@ func FiletypeSupported(ext string) bool {
}
func (this *Thumbnailer) RenderFile_NoCache(absPath string) ([]byte, error) {
return this.RenderFile_NoCache_MimeType(absPath, mime.TypeByExtension(filepath.Ext(absPath)))
}
func (this *Thumbnailer) RenderFile_NoCache_MimeType(absPath, mimeType string) ([]byte, error) {
fh, err := os.OpenFile(absPath, os.O_RDONLY, 0400)
if err != nil {
return nil, err
}
defer fh.Close()
extension := strings.ToLower(filepath.Ext(absPath))
switch extension {
case ".jpg", ".jpeg":
if mimeType == `image/jpeg` {
src, err := jpeg.Decode(fh)
if err != nil {
return nil, err
@ -111,7 +111,7 @@ func (this *Thumbnailer) RenderFile_NoCache(absPath string) ([]byte, error) {
return this.RenderScaledImage(src)
case ".png":
} else if mimeType == `image/png` {
src, err := png.Decode(fh)
if err != nil {
return nil, err
@ -119,7 +119,7 @@ func (this *Thumbnailer) RenderFile_NoCache(absPath string) ([]byte, error) {
return this.RenderScaledImage(src)
case ".gif":
} else if mimeType == `image/gif` {
src, err := gif.Decode(fh)
if err != nil {
return nil, err
@ -127,10 +127,10 @@ func (this *Thumbnailer) RenderFile_NoCache(absPath string) ([]byte, error) {
return this.RenderScaledImage(src)
case ".avi", ".mkv", ".mp4", ".ogm", ".wmv", ".flv", ".rm", ".rmvb":
} else if strings.HasPrefix(mimeType, `video/`) {
return this.RenderScaledFfmpeg(absPath)
default:
} else {
return nil, ErrUnsupportedFiletype
}