Skip to content

Commit

Permalink
fix: auto add file extension for download file.
Browse files Browse the repository at this point in the history
  • Loading branch information
syhily committed Nov 25, 2022
1 parent 7d62f5c commit bd8277f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions internal/fetcher/k12.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ func (k *k12Service) formats(id int64) (map[file.Format]driver.Share, error) {
}

return map[file.Format]driver.Share{
file.PDF: {
FileName: book.Title + "." + book.CustomProperties.Format,
file.Format(book.CustomProperties.Format): {
FileName: book.Title,
SubPath: subPath,
Size: book.CustomProperties.Size,
URL: book.ID,
Expand Down
5 changes: 4 additions & 1 deletion internal/file/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"path/filepath"
"strconv"
"strings"

"github.com/schollz/progressbar/v3"

Expand Down Expand Up @@ -52,8 +53,10 @@ func (c *creator) NewWriter(id, total int64, name, subPath string, format Format
filename := strconv.FormatInt(id, 10)
if c.rename {
filename = filename + "." + string(format)
} else if strings.HasSuffix(name, "."+string(format)) {
filename = name
} else {
filename = filename + "_" + name
filename = name + "." + string(format)
}

// Escape the file name for avoiding the illegal characters.
Expand Down

0 comments on commit bd8277f

Please sign in to comment.