Attemping to fix bulk upload problem

This commit is contained in:
2026-07-12 16:11:02 -04:00
parent 119d4100b5
commit b075433e6e
6 changed files with 68 additions and 13 deletions
+37 -3
View File
@@ -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
}
+8 -3
View File
@@ -1,9 +1,10 @@
package handler
import (
"bytes"
"html/template"
"io"
"log"
"net/http"
)
type Templates struct {
@@ -13,8 +14,12 @@ type Templates struct {
func NewTemplates(tmpl *template.Template) *Templates {
return &Templates{tmpl: tmpl}
}
func (t *Templates) Render(w io.Writer, name string, data any) {
if err := t.tmpl.ExecuteTemplate(w, name+".html", data); err != nil {
func (t *Templates) Render(w http.ResponseWriter, name string, data any) {
var buf bytes.Buffer
if err := t.tmpl.ExecuteTemplate(&buf, name+".html", data); err != nil {
log.Printf("template error: %s: %v", name, err)
http.Error(w, "Internal server error", http.StatusInternalServerError)
return
}
w.Write(buf.Bytes())
}