dont cancel curl commands during execution

This commit is contained in:
milarin 2023-03-07 19:48:18 +01:00
parent 2787b57189
commit eafaeb43a4
2 changed files with 7 additions and 7 deletions

6
api.go
View File

@ -77,7 +77,7 @@ func (api *Api) GetReadingList(ctx context.Context, listIndex int) (*ReadingList
} }
func (api *Api) GetNovelByID(novelID NovelID) (*Novel, error) { func (api *Api) GetNovelByID(novelID NovelID) (*Novel, error) {
doc, err := api.Get(context.Background(), fmt.Sprintf("https://www.novelupdates.com/series/%s/", novelID)) doc, err := api.Get(fmt.Sprintf("https://www.novelupdates.com/series/%s/", novelID))
if err != nil { if err != nil {
return nil, ErrApiRequestFailed.Wrap(err) return nil, ErrApiRequestFailed.Wrap(err)
} }
@ -135,7 +135,7 @@ func (api *Api) GetChapterEntriesByNovelID(novelID NovelID) *Cursor[NovelChapter
go func() { go func() {
defer close(out) defer close(out)
doc, err := api.Get(ctx, fmt.Sprintf("https://www.novelupdates.com/series/%s/?pg=%d", novelID, 1)) doc, err := api.Get(fmt.Sprintf("https://www.novelupdates.com/series/%s/?pg=%d", novelID, 1))
if err != nil { if err != nil {
fmt.Fprintln(os.Stderr, err) fmt.Fprintln(os.Stderr, err)
return return
@ -190,7 +190,7 @@ func (api *Api) getPageCount(doc *goquery.Document) (int, error) {
} }
func (api *Api) getChapterEntriesByPageIndex(ctx context.Context, novelID NovelID, pageIndex int) ([]NovelChapterEntry, error) { func (api *Api) getChapterEntriesByPageIndex(ctx context.Context, novelID NovelID, pageIndex int) ([]NovelChapterEntry, error) {
doc, err := api.Get(ctx, fmt.Sprintf("https://www.novelupdates.com/series/%s/?pg=%d", novelID, pageIndex)) doc, err := api.Get(fmt.Sprintf("https://www.novelupdates.com/series/%s/?pg=%d", novelID, pageIndex))
if err != nil { if err != nil {
return nil, ErrApiRequestFailed.Wrap(err) return nil, ErrApiRequestFailed.Wrap(err)
} }

View File

@ -14,7 +14,7 @@ func (api *Api) GetWithCookie(ctx context.Context, url string) (*goquery.Documen
return nil, ErrNoCookieSet.New() return nil, ErrNoCookieSet.New()
} }
curl := exec.CommandContext(ctx, "curl", curl := exec.Command("curl",
"-s", url, "-s", url,
"-H", fmt.Sprintf("User-Agent: %s", api.UserAgent), "-H", fmt.Sprintf("User-Agent: %s", api.UserAgent),
"-H", fmt.Sprintf("Cookie: %s", api.Cookie), "-H", fmt.Sprintf("Cookie: %s", api.Cookie),
@ -39,8 +39,8 @@ func (api *Api) GetWithCookie(ctx context.Context, url string) (*goquery.Documen
return goquery.NewDocumentFromReader(r) return goquery.NewDocumentFromReader(r)
} }
func (api *Api) Get(ctx context.Context, url string) (*goquery.Document, error) { func (api *Api) Get(url string) (*goquery.Document, error) {
curl := exec.CommandContext(ctx, "curl", curl := exec.Command("curl",
"-s", url, "-s", url,
"-H", fmt.Sprintf("User-Agent: %s", api.UserAgent), "-H", fmt.Sprintf("User-Agent: %s", api.UserAgent),
"-H", fmt.Sprintf("Accept-Encoding: %s", "gzip"), "-H", fmt.Sprintf("Accept-Encoding: %s", "gzip"),
@ -58,7 +58,7 @@ func (api *Api) Get(ctx context.Context, url string) (*goquery.Document, error)
r, err := gzip.NewReader(stdout) r, err := gzip.NewReader(stdout)
if err != nil { if err != nil {
return nil, ErrInvalidGzipData.New(err) return nil, ErrInvalidGzipData.Wrap(err)
} }
return goquery.NewDocumentFromReader(r) return goquery.NewDocumentFromReader(r)