Skip to content

Commit 8702be7

Browse files
authored
Merge pull request #7 from upwell/fix_download_url
file.Href might be full URL
2 parents a373e8b + 1ce21c4 commit 8702be7

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

talebook.go

+13-4
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ func (b Book) String() string {
107107
}
108108

109109
func (tale *TaleBook) Request(req *http.Request) (*http.Response, error) {
110-
return tale.retryReuquest(req, 0)
110+
return tale.tryRequest(req, 0)
111111
}
112-
func (tale *TaleBook) retryReuquest(req *http.Request, count int) (*http.Response, error) {
112+
func (tale *TaleBook) tryRequest(req *http.Request, count int) (*http.Response, error) {
113113
if tale.userAgent != "" {
114114
req.Header.Set("User-Agent", tale.userAgent)
115115
}
@@ -122,7 +122,7 @@ func (tale *TaleBook) retryReuquest(req *http.Request, count int) (*http.Respons
122122
return nil, err
123123
}
124124
log.Printf("timeout , retry %s://%s%s [%d/%d]", req.URL.Scheme, req.Host, req.URL.Path, count+1, tale.retry)
125-
return tale.retryReuquest(req, count+1)
125+
return tale.tryRequest(req, count+1)
126126
}
127127
return response, err
128128
}
@@ -160,7 +160,16 @@ func (tale *TaleBook) Next() (*Book, error) {
160160

161161
func (tale *TaleBook) Download(b *Book, dir string) error {
162162
for _, file := range b.Book.Files {
163-
downloadURL := urlJoin(tale.api, file.Href)
163+
var downloadURL string
164+
if strings.HasPrefix(file.Href, "https://") || strings.HasPrefix(file.Href, "http://") {
165+
downloadURL = file.Href
166+
} else {
167+
downloadURL = urlJoin(tale.api, file.Href)
168+
}
169+
if tale.verbose {
170+
log.Printf("download %s", downloadURL)
171+
}
172+
164173
req, err := http.NewRequest(http.MethodGet, downloadURL, nil)
165174
if err != nil {
166175
return err

0 commit comments

Comments
 (0)