2023-07-06 13:25:51 +02:00
|
|
|
package fetch
|
2023-05-10 16:28:45 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
2023-05-27 14:36:22 +02:00
|
|
|
|
|
|
|
"miniflux.app/client"
|
2023-05-10 16:28:45 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type Entry struct {
|
|
|
|
MinifluxEntryID string
|
|
|
|
MinifluxFeedID string
|
|
|
|
MinifluxURL string
|
|
|
|
Title string
|
|
|
|
Description string
|
|
|
|
}
|
|
|
|
|
|
|
|
type MinifluxInfo struct {
|
|
|
|
Endpoint string
|
|
|
|
ApiKey string
|
|
|
|
}
|
|
|
|
|
|
|
|
type Miniflux struct {
|
|
|
|
client *client.Client
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewMiniflux(mflInfo MinifluxInfo) *Miniflux {
|
|
|
|
return &Miniflux{
|
|
|
|
client: client.New(mflInfo.Endpoint, mflInfo.ApiKey),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Miniflux) Unread() ([]FeedEntry, error) {
|
|
|
|
result, err := m.client.Entries(&client.Filter{Status: "unread"})
|
|
|
|
if err != nil {
|
2023-05-27 14:36:22 +02:00
|
|
|
return nil, err
|
2023-05-10 16:28:45 +02:00
|
|
|
}
|
|
|
|
|
2023-05-27 14:36:22 +02:00
|
|
|
entries := make([]FeedEntry, 0, len(result.Entries))
|
2023-05-10 16:28:45 +02:00
|
|
|
for _, entry := range result.Entries {
|
|
|
|
entries = append(entries, FeedEntry{
|
2023-05-27 14:36:22 +02:00
|
|
|
EntryID: entry.ID,
|
|
|
|
FeedID: entry.FeedID,
|
|
|
|
YoutubeChannelID: strings.TrimPrefix(entry.Feed.FeedURL, "https://www.youtube.com/feeds/videos.xml?channel_id="),
|
|
|
|
YoutubeID: strings.TrimPrefix(entry.URL, "https://www.youtube.com/watch?v="),
|
2023-05-10 16:28:45 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return entries, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Miniflux) MarkRead(entryID int64) error {
|
|
|
|
if err := m.client.UpdateEntries([]int64{entryID}, "read"); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|