Skip to content

Commit

Permalink
For simplicity, thumbnail doesn't need any extension
Browse files Browse the repository at this point in the history
  • Loading branch information
RadhiFadlillah committed May 24, 2019
1 parent e65dd22 commit 268aeb2
Showing 1 changed file with 0 additions and 20 deletions.
20 changes: 0 additions & 20 deletions internal/cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"io"
"mime"
"net/http"
nurl "net/url"
"os"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 268aeb2

Please sign in to comment.