more correct extension handling
This commit is contained in:
parent
b5fe725836
commit
b1c3e5c15f
@ -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)
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user