Attemping to fix bulk upload problem
This commit is contained in:
+37
-3
@@ -1,6 +1,7 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -126,8 +127,20 @@ func (h *ImportHandler) ServeImport(w http.ResponseWriter, r *http.Request) {
|
||||
})
|
||||
}
|
||||
|
||||
var rssHTTPClient = &http.Client{
|
||||
Timeout: 30 * time.Second,
|
||||
}
|
||||
|
||||
func (h *ImportHandler) fetchRSS(rssURL string) ([]ImportEpisodeView, error) {
|
||||
resp, err := http.Get(rssURL)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel()
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, rssURL, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err := rssHTTPClient.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -180,7 +193,16 @@ func (h *ImportHandler) importSelected(w http.ResponseWriter, r *http.Request, r
|
||||
}
|
||||
}
|
||||
|
||||
resp, err := http.Get(rssURL)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel()
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, rssURL, nil)
|
||||
if err != nil {
|
||||
http.Redirect(w, r, "/import?error=failed+to+fetch+rss", http.StatusSeeOther)
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := rssHTTPClient.Do(req)
|
||||
if err != nil {
|
||||
http.Redirect(w, r, "/import?error=failed+to+fetch+rss", http.StatusSeeOther)
|
||||
return
|
||||
@@ -255,8 +277,20 @@ func (h *ImportHandler) episodeImageURL(item *importItem, channel *importChannel
|
||||
return ""
|
||||
}
|
||||
|
||||
var importHTTPClient = &http.Client{
|
||||
Timeout: 5 * time.Minute,
|
||||
}
|
||||
|
||||
func (h *ImportHandler) downloadFile(url, category string) (string, error) {
|
||||
resp, err := http.Get(url)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
||||
defer cancel()
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
resp, err := importHTTPClient.Do(req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user