aboutsummaryrefslogtreecommitdiff
path: root/internal/feed/cache_v1.go
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--internal/feed/cache_v1.go51
1 files changed, 50 insertions, 1 deletions
diff --git a/internal/feed/cache_v1.go b/internal/feed/cache_v1.go
index 02890e1..b5d6b3e 100644
--- a/internal/feed/cache_v1.go
+++ b/internal/feed/cache_v1.go
@@ -6,6 +6,7 @@ import (
"encoding/hex"
"fmt"
"strconv"
+ "strings"
"time"
"github.com/google/uuid"
@@ -25,6 +26,11 @@ func (id feedId) String() string {
return strconv.FormatUint(uint64(id), 16)
}
+func idFromString(s string) feedId {
+ id, _ := strconv.ParseUint(s, 16, 64)
+ return feedId(id)
+}
+
type v1Cache struct {
Ids map[feedDescriptor]feedId
NextId uint64
@@ -58,12 +64,15 @@ type cachedItem struct {
func (item cachedItem) String() string {
return fmt.Sprintf(`{
+ ID: %s
Title: %q
Guid: %q
Link: %q
Date: %s
Hash: %s
-}`, item.Title, item.Guid, item.Link, util.TimeFormat(item.Date), item.Hash)
+}`,
+ base64.RawURLEncoding.EncodeToString(item.ID[:]),
+ item.Title, item.Guid, item.Link, util.TimeFormat(item.Date), item.Hash)
}
func (cf *cachedFeed) Checked(withFailure bool) {
@@ -97,6 +106,46 @@ func (cache *v1Cache) Version() Version {
return v1Version
}
+func (cache *v1Cache) Info() string {
+ b := strings.Builder{}
+ for descr, id := range cache.Ids {
+ b.WriteString(fmt.Sprintf("%3s: %s (%s)\n", id.String(), descr.Name, descr.Url))
+ }
+ return b.String()
+}
+
+func (cache *v1Cache) SpecificInfo(i interface{}) string {
+ id := idFromString(i.(string))
+
+ b := strings.Builder{}
+ feed := cache.Feeds[id]
+
+ for descr, fId := range cache.Ids {
+ if id == fId {
+ b.WriteString(descr.Name)
+ b.WriteString(" -- ")
+ b.WriteString(descr.Url)
+ b.WriteByte('\n')
+ break
+ }
+ }
+
+ b.WriteString(fmt.Sprintf(`
+Last Check: %s
+Num Failures: %d
+Num Items: %d
+`,
+ util.TimeFormat(feed.LastCheck),
+ feed.NumFailures,
+ len(feed.Items)))
+
+ for _, item := range feed.Items {
+ b.WriteString("\n--------------------\n")
+ b.WriteString(item.String())
+ }
+ return b.String()
+}
+
func newV1Cache() *v1Cache {
cache := v1Cache{
Ids: map[feedDescriptor]feedId{},