add /feeds/{feed} endpoint, show feed failures to user
Jes Olson j3s@c3f.net
Fri, 15 Sep 2023 01:34:27 -0500
5 files changed,
58 insertions(+),
18 deletions(-)
A
files/feedDetails.tmpl.html
@@ -0,0 +1,21 @@
+{{ define "feedDetails" }} +{{ template "head" . }} +{{ template "nav" . }} +<h3>{{ .Data.Feed.UpdateURL }}</h3> +<p> +Title: {{ .Data.Feed.Title }} +Description: {{ .Data.Feed.Description }} +Next Refresh: {{ .Data.Feed.Refresh }} +Last Fetch Failure: {{ .Data.FetchFailure }} +</p> +{{ len .Data.Feed.Items }} Items:</p> +{{ range .Data.Feed.Items }} +<details> +<summary>{{ .Title }}</summary> +<p>Date: {{ .Date }} +Link: <a href="{{ .Link }}">{{ .Link }}</a> +</p> +</details> +{{ end }} +{{ template "tail" . }} +{{ end }}
M
files/settings.tmpl.html
→
files/settings.tmpl.html
@@ -48,25 +48,12 @@ ( . .)
( づ♡ </p> {{ else if gt $length 0 }} -<p>feed details:</p> +<p>feed details 👁️👄👁️</p> {{ end }} -{{ range .Data }} -<details> - <summary>{{ .UpdateURL }}</summary> -<p>Title: {{ .Title | trimSpace }} -Description: "{{ .Description | trimSpace }}" -Refresh: {{ .Refresh.Format "Jan 02, 15:04:05 UTC" }} -{{ len .Items }} Items:</p> -{{ range .Items }} -<details> - <summary>{{ .Title }}</summary> -<p>Date: {{ .Date }} -Link: {{ .Link }} +<p> +{{ range .Data -}} +<a href="/feeds/{{ .UpdateURL | escapeURL }}">{{ .UpdateURL }}</a> +{{ end -}} </p> -</details> -{{ end }} -</p> -</details> -{{ end }} {{ template "tail" . }} {{ end }}
M
main.go
→
main.go
@@ -22,6 +22,7 @@ mux.HandleFunc("POST /login", s.loginHandler)
mux.HandleFunc("GET /logout", s.logoutHandler) mux.HandleFunc("POST /logout", s.logoutHandler) mux.HandleFunc("POST /register", s.registerHandler) + mux.HandleFunc("GET /feeds/{url}", s.feedDetailsHandler) // left in-place for backwards compat mux.HandleFunc("GET /feeds", s.settingsHandler)
M
reaper/reaper.go
→
reaper/reaper.go
@@ -102,6 +102,10 @@ }
return false } +func (r *Reaper) GetFeed(url string) *rss.Feed { + return r.feeds[url] +} + // GetUserFeeds returns a list of feeds func (r *Reaper) GetUserFeeds(username string) []*rss.Feed { urls := r.db.GetUserFeedURLs(username)
M
site.go
→
site.go
@@ -197,6 +197,32 @@ }
http.Redirect(w, r, "/settings", http.StatusSeeOther) } +func (s *Site) feedDetailsHandler(w http.ResponseWriter, r *http.Request) { + encodedURL := muxpatterns.PathValue(r, "url") + decodedURL, err := url.QueryUnescape(encodedURL) + if err != nil { + e := fmt.Sprintf("failed to decode URL '%s' %s", encodedURL, err) + s.renderErr(w, e, http.StatusBadRequest) + return + } + fetchErr, err := s.db.GetFeedFetchError(decodedURL) + if err != nil { + e := fmt.Sprintf("failed to fetch feed error '%s' %s", encodedURL, err) + s.renderErr(w, e, http.StatusBadRequest) + return + } + + feedData := struct { + Feed *rss.Feed + FetchFailure string + }{ + Feed: s.reaper.GetFeed(decodedURL), + FetchFailure: fetchErr, + } + + s.renderPage(w, r, "feedDetails", feedData) +} + // username fetches a client's username based // on the sessionToken that user has set. username // will return "" if there is no sessionToken.@@ -279,6 +305,7 @@ funcMap := template.FuncMap{
"printDomain": s.printDomain, "timeSince": s.timeSince, "trimSpace": strings.TrimSpace, + "escapeURL": url.QueryEscape, } tmplFiles := filepath.Join("files", "*.tmpl.html")