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