From 68b9f06ad0af4c7574f57acefe8ddc56b6bd87ba Mon Sep 17 00:00:00 2001 From: laureanray Date: Fri, 14 Jul 2023 00:38:27 +0800 Subject: [PATCH] update downloader to prepand path --- internal/downloader/downloader.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/downloader/downloader.go b/internal/downloader/downloader.go index dab4bcd..8ebc994 100644 --- a/internal/downloader/downloader.go +++ b/internal/downloader/downloader.go @@ -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, } } @@ -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()