convert pbPost to post

This commit is contained in:
Travis Shears 2025-09-28 12:18:33 +02:00
parent 506a12c06c
commit ef5f5e33ab
2 changed files with 34 additions and 12 deletions

View file

@ -20,11 +20,12 @@ const (
sourceNostr source = "nostr"
)
var supportedSources = []source{
sourceNostr,
// TODO: Add support for BlueSky and Mastodon
// SourceBlueSky,
// SourceMastodon,
var supportedSources = map[source]bool{
sourceNostr: true,
sourcePleroma: false,
sourceBlueSky: false,
sourceMastodon: false,
sourcePixelfed: false,
}
// Post represents a single blog post
@ -46,6 +47,10 @@ type pbPost struct {
Posted string `json:"posted"`
}
type nostrPost struct {
Content string `json:"content"`
}
// MicroBlog manages blog posts
type MicroBlog struct {
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)
}
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