For simplicity, thumbnail doesn't need any extension

This commit is contained in:
Radhi Fadlillah 2019-05-24 16:24:16 +07:00
parent e65dd220d4
commit 268aeb2b28

View file

@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"io"
"mime"
"net/http"
nurl "net/url"
"os"
@ -73,25 +72,6 @@ func downloadBookImage(url, dstPath string, timeout time.Duration) error {
return err
}
// If destination path doesn't have extension, create it
if fp.Ext(dstPath) == "" {
cp := resp.Header.Get("Content-Type")
if !strings.Contains(cp, "image/") {
return fmt.Errorf("%s is not an image", url)
}
exts, err := mime.ExtensionsByType(cp)
if err != nil {
return fmt.Errorf("failed to create extension: %v", err)
}
if len(exts) == 0 {
return fmt.Errorf("unknown content type")
}
dstPath += exts[0]
}
// Create destination file
dst, err := os.Create(dstPath)
if err != nil {