diff --git a/handler/handle_news.go b/handler/handle_news.go index 7cbe8a2..c6a0fa2 100644 --- a/handler/handle_news.go +++ b/handler/handle_news.go @@ -127,10 +127,13 @@ func handleNews(w http.ResponseWriter, r *http.Request) { cat := r.URL.Query().Get("cat") if cat != "" { - sources, err := dao.GetSources(ctx, u.ID) - if err != nil { - http.Error(w, "Error getting sources", 500) - return + sources := domain.GetSources() + if u != nil { + sources, err = dao.GetSources(ctx, u.ID) + if err != nil { + http.Error(w, "Error getting sources", 500) + return + } } sourceCats := make(map[string][]string) for _, s := range sources { @@ -246,6 +249,10 @@ top: size -= 100 goto top } else if len(candidates) == 0 { + if image { + image = false + goto top + } return domain.Article{} } sort.Slice(candidates, func(i, j int) bool { diff --git a/handler/pubsub_source.go b/handler/pubsub_source.go index 097d609..4756c4d 100644 --- a/handler/pubsub_source.go +++ b/handler/pubsub_source.go @@ -2,6 +2,7 @@ package handler import ( "encoding/json" + "github.com/arussellsaw/news/dao" "math/rand" "net/http" "strings" @@ -44,7 +45,15 @@ func handlePubsubSource(w http.ResponseWriter, r *http.Request) { } for _, item := range feed.Items { - err := p.Publish(ctx, "articles", ArticleEvent{ + a, err := dao.GetArticleByURL(ctx, item.Link) + if err != nil { + slog.Error(ctx, "Error getting article: %s", err) + continue + } + if a != nil { + continue + } + err = p.Publish(ctx, "articles", ArticleEvent{ Article: domain.Article{ Title: strings.TrimSpace(item.Title), Description: item.Description, diff --git a/tmpl/article.html b/tmpl/article.html index bb57d1e..4a2186f 100644 --- a/tmpl/article.html +++ b/tmpl/article.html @@ -23,8 +23,10 @@ {{end}} {{end}} + {{if .User}} {{if .User.IsAdmin }} Refresh {{end}} + {{end}} {{ end }}