From c158912da4e8d6526f8f3ac6b05c3258daf0d8a6 Mon Sep 17 00:00:00 2001 From: Nadia Santalla Date: Sun, 27 Jul 2025 16:55:57 +0200 Subject: [PATCH] fix media_links reading from DB Prior to this commit, `MediaLinks` were always returned as `nil`. Peeking a bit I figured that's becuase the argument to `MediaLinks.Scan` is in fact a string, and not a `[]byte` as the code expects. I guess that might be because `media_links` is a `json` (not `jsonb`) column in sqlite. I have no idea which of the two is best to use for the DB side, but it's easy to make the code support both. --- src/storage/item.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/storage/item.go b/src/storage/item.go index 9af1197..367d80b 100644 --- a/src/storage/item.go +++ b/src/storage/item.go @@ -54,10 +54,14 @@ type MediaLink struct { type MediaLinks []MediaLink func (m *MediaLinks) Scan(src any) error { - if data, ok := src.([]byte); ok { + switch data := src.(type) { + case []byte: return json.Unmarshal(data, m) + case string: + return json.Unmarshal([]byte(data), m) + default: + return nil } - return nil } func (m MediaLinks) Value() (driver.Value, error) { @@ -419,7 +423,6 @@ func (s *Storage) DeleteOldItems() { where status != ? group by i.feed_id `, itemsKeepSize, STARRED) - if err != nil { log.Print(err) return