package main import ( "context" "errors" "os" miniflux "miniflux.app/client" ) var _ Source = &MinifluxFeed{} type MinifluxFeed struct { name string endpoint string feedId int64 language Language client *miniflux.Client } func (m *MinifluxFeed) getClient() error { token := os.Getenv("MINIFLUX_SECRET_TOKEN") if token == "" { return errors.New("MINIFLUX_SECRET_TOKEN not set") } m.client = miniflux.New(m.endpoint, token) return nil } func (m *MinifluxFeed) Name() string { return m.name } func (m *MinifluxFeed) Language() Language { return m.language } func (m *MinifluxFeed) Len(ctx context.Context) (int, error) { if m.client == nil { if err := m.getClient(); err != nil { return -1, err } } entries, err := m.client.FeedEntries(m.feedId, &miniflux.Filter{Status: miniflux.EntryStatusUnread}) if err != nil { return -1, err } return entries.Total, nil } func (m *MinifluxFeed) Get(ctx context.Context, i int) (*Article, error) { if m.client == nil { if err := m.getClient(); err != nil { return nil, err } } entries, err := m.client.FeedEntries(m.feedId, &miniflux.Filter{ Status: miniflux.EntryStatusUnread, Direction: "desc", Order: "published_at"}) if err != nil { return nil, err } entry := entries.Entries[i] if err := m.client.UpdateEntries([]int64{entry.ID}, "read"); err != nil { return nil, err } return &Article{raw: extractText(entry.Content)}, nil }