repos / pico

pico services - prose.sh, pastes.sh, imgs.sh, feeds.sh, pgs.sh
git clone https://github.com/picosh/pico.git

commit
0751d5d
parent
d6d75f7
author
Eric Bower
date
2022-08-27 04:30:44 +0000 UTC
fix(rss): lists set proper rss entries for blog
2 files changed,  +14, -6
M imgs/api.go
+10, -2
 1@@ -382,8 +382,16 @@ func rssBlogHandler(w http.ResponseWriter, r *http.Request) {
 2 		return
 3 	}
 4 
 5-	pager, err := dbpool.FindPostsForUser(&db.Pager{Num: 10, Page: 0}, user.ID, cfg.Space)
 6-	posts := pager.Data
 7+	tag := r.URL.Query().Get("tag")
 8+	var posts []*db.Post
 9+	var p *db.Paginate[*db.Post]
10+	pager := &db.Pager{Num: 10, Page: 0}
11+	if tag == "" {
12+		p, err = dbpool.FindPostsForUser(pager, user.ID, cfg.Space)
13+	} else {
14+		p, err = dbpool.FindUserPostsByTag(pager, tag, user.ID, cfg.Space)
15+	}
16+	posts = p.Data
17 
18 	if err != nil {
19 		logger.Error(err)
M lists/api.go
+4, -4
 1@@ -87,13 +87,13 @@ type ReadmeTxt struct {
 2 	Items    []*ListItem
 3 }
 4 
 5-func getPostsForUser(r *http.Request, user *db.User, tag string) ([]*db.Post, error) {
 6+func getPostsForUser(r *http.Request, user *db.User, tag string, num int) ([]*db.Post, error) {
 7 	dbpool := shared.GetDB(r)
 8 	cfg := shared.GetCfg(r)
 9 	var err error
10 
11 	posts := make([]*db.Post, 0)
12-	pager := &db.Pager{Num: 1000, Page: 0}
13+	pager := &db.Pager{Num: num, Page: 0}
14 	var p *db.Paginate[*db.Post]
15 	if tag == "" {
16 		p, err = dbpool.FindPostsForUser(pager, user.ID, cfg.Space)
17@@ -131,7 +131,7 @@ func blogHandler(w http.ResponseWriter, r *http.Request) {
18 	}
19 
20 	tag := r.URL.Query().Get("tag")
21-	posts, err := getPostsForUser(r, user, tag)
22+	posts, err := getPostsForUser(r, user, tag, 1000)
23 	if err != nil {
24 		logger.Error(err)
25 		http.Error(w, "could not fetch posts for blog", http.StatusInternalServerError)
26@@ -503,7 +503,7 @@ func rssBlogHandler(w http.ResponseWriter, r *http.Request) {
27 	}
28 
29 	tag := r.URL.Query().Get("tag")
30-	posts, err := getPostsForUser(r, user, tag)
31+	posts, err := getPostsForUser(r, user, tag, 10)
32 	if err != nil {
33 		logger.Error(err)
34 		http.Error(w, "could not fetch posts for blog", http.StatusInternalServerError)