more correct extension handling

This commit is contained in:
mappu 2016-12-05 19:03:05 +13:00
parent b5fe725836
commit b1c3e5c15f

View File

@ -5,6 +5,7 @@ import (
"image/jpeg"
"image/png"
"os"
"path/filepath"
"strings"
lru "github.com/hashicorp/golang-lru"
@ -56,13 +57,10 @@ func (this *Thumbnailer) RenderFile_NoCache(absPath string) ([]byte, error) {
defer fh.Close()
if len(absPath) < 4 {
return nil, fmt.Errorf("No extension on filename")
}
extension := strings.ToLower(absPath[len(absPath)-4:])
extension := strings.ToLower(filepath.Ext(absPath))
switch extension {
case ".jpg", "jpeg":
case "jpg", "jpeg":
src, err := jpeg.Decode(fh)
if err != nil {
return nil, err
@ -70,7 +68,7 @@ func (this *Thumbnailer) RenderFile_NoCache(absPath string) ([]byte, error) {
return this.RenderScaledImage(src)
case ".png":
case "png":
src, err := png.Decode(fh)
if err != nil {
return nil, err
@ -78,11 +76,11 @@ func (this *Thumbnailer) RenderFile_NoCache(absPath string) ([]byte, error) {
return this.RenderScaledImage(src)
case ".avi", ".mkv", ".mp4", ".ogm", ".wmv":
case "avi", "mkv", "mp4", "ogm", "wmv":
return this.RenderScaledFfmpeg(absPath)
default:
return nil, fmt.Errorf("No thumbnailer for file type")
return nil, fmt.Errorf("No thumbnailer for file type '%s'", extension)
}