convert pbPost to post
This commit is contained in:
parent
506a12c06c
commit
ef5f5e33ab
2 changed files with 34 additions and 12 deletions
|
|
@ -20,11 +20,12 @@ const (
|
||||||
sourceNostr source = "nostr"
|
sourceNostr source = "nostr"
|
||||||
)
|
)
|
||||||
|
|
||||||
var supportedSources = []source{
|
var supportedSources = map[source]bool{
|
||||||
sourceNostr,
|
sourceNostr: true,
|
||||||
// TODO: Add support for BlueSky and Mastodon
|
sourcePleroma: false,
|
||||||
// SourceBlueSky,
|
sourceBlueSky: false,
|
||||||
// SourceMastodon,
|
sourceMastodon: false,
|
||||||
|
sourcePixelfed: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Post represents a single blog post
|
// Post represents a single blog post
|
||||||
|
|
@ -46,6 +47,10 @@ type pbPost struct {
|
||||||
Posted string `json:"posted"`
|
Posted string `json:"posted"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type nostrPost struct {
|
||||||
|
Content string `json:"content"`
|
||||||
|
}
|
||||||
|
|
||||||
// MicroBlog manages blog posts
|
// MicroBlog manages blog posts
|
||||||
type MicroBlog struct {
|
type MicroBlog struct {
|
||||||
pbClient *pocketbase.PocketBaseClient
|
pbClient *pocketbase.PocketBaseClient
|
||||||
|
|
@ -124,7 +129,25 @@ func (mb *MicroBlog) GetRecentPosts(limit int) ([]post, error) {
|
||||||
return nil, fmt.Errorf("failed to decode response: %w", err)
|
return nil, fmt.Errorf("failed to decode response: %w", err)
|
||||||
}
|
}
|
||||||
slog.Info("Posts from pocketbase", "rawPosts", rawPosts)
|
slog.Info("Posts from pocketbase", "rawPosts", rawPosts)
|
||||||
return nil, fmt.Errorf("todo: %w", err)
|
|
||||||
|
var filteredPosts []post
|
||||||
|
for _, p := range rawPosts {
|
||||||
|
if p.Source == SourceNostr {
|
||||||
|
var nostrPost nostrPost
|
||||||
|
if err := json.Unmarshal(p.FullPost, &nostrPost); err != nil {
|
||||||
|
slog.Error("Problem unmarshalling nostr post", "error", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
filteredPosts = append(filteredPosts, post{
|
||||||
|
ID: p.ID,
|
||||||
|
RemoteID: p.RemoteID,
|
||||||
|
Content: nostrPost.Content,
|
||||||
|
Timestamp: time.Now(),
|
||||||
|
})
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return filteredPosts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// HandleBlogRequest handles Gemini requests for the microblog
|
// HandleBlogRequest handles Gemini requests for the microblog
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log/slog"
|
||||||
|
|
||||||
"gemini_site/internal/microblog"
|
"gemini_site/internal/microblog"
|
||||||
"gemini_site/internal/pocketbase"
|
"gemini_site/internal/pocketbase"
|
||||||
|
|
@ -11,14 +11,13 @@ import (
|
||||||
func main() {
|
func main() {
|
||||||
pbClient := pocketbase.NewPocketBaseClient()
|
pbClient := pocketbase.NewPocketBaseClient()
|
||||||
mb := microblog.NewMicroBlog(pbClient)
|
mb := microblog.NewMicroBlog(pbClient)
|
||||||
res, err := mb.GetRecentPosts(2)
|
res, err := mb.GetRecentPosts(10)
|
||||||
// res, err := pbClient.GetList("micro_blog_posts", 1, 10, "-posted")
|
// res, err := pbClient.GetList("micro_blog_posts", 1, 10, "-posted")
|
||||||
fmt.Println("Getting page 1 of microblog posts")
|
fmt.Println("Getting page 1 of microblog posts, 10 posts")
|
||||||
// posts, err := client.GetPosts(1)
|
// posts, err := client.GetPosts(1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error getting posts: %v", err)
|
slog.Error("Error getting posts", "error", err)
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("Got first page of microblog posts\n")
|
slog.Info("Got microblog posts", "posts", res)
|
||||||
fmt.Printf("First post: %v\n", res)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue