Skip to content

Commit

Permalink
update downloader to prepand path
Browse files Browse the repository at this point in the history
  • Loading branch information
laureanray committed Jul 13, 2023
1 parent 4eb4d88 commit 68b9f06
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions internal/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ import (
type Downloader struct {
selectedBook book.Book
directLink string
outputFileDir string
}

func NewDownloader(selectedBook book.Book, directLink string) *Downloader {
func NewDownloader(selectedBook book.Book, directLink string, outputFileDir string) *Downloader {
return &Downloader{
selectedBook: selectedBook,
directLink: directLink,
outputFileDir: outputFileDir,
}
}

Expand All @@ -37,7 +39,7 @@ func (d *Downloader) Download() error {
}

defer resp.Body.Close()
filename := sanitize.Path(strings.Trim(d.selectedBook.Title, " ") + "." + d.selectedBook.Extension)
filename := sanitize.Path(d.outputFileDir + strings.Trim(d.selectedBook.Title, " ") + "." + d.selectedBook.Extension)

f, _ := os.OpenFile(filename, os.O_CREATE|os.O_WRONLY, 0666)
defer f.Close()
Expand Down

0 comments on commit 68b9f06

Please sign in to comment.