diff options
author | Frédéric Guillot <fred@miniflux.net> | 2017-12-16 11:25:18 -0800 |
---|---|---|
committer | Frédéric Guillot <fred@miniflux.net> | 2017-12-16 11:25:18 -0800 |
commit | 27196589fbd36f5f840e51b59bd6253d0f865db3 (patch) | |
tree | 4896268c735528045e4064ace92a2a75280585b8 /storage | |
parent | 231ebf2daa9c024fbe99277f57935444946824bd (diff) |
Add FeedIcon API call and update dependencies
Diffstat (limited to 'storage')
-rw-r--r-- | storage/icon.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/storage/icon.go b/storage/icon.go index 1f38938..f5c71cb 100644 --- a/storage/icon.go +++ b/storage/icon.go @@ -38,6 +38,28 @@ func (s *Storage) IconByID(iconID int64) (*model.Icon, error) { return &icon, nil } +// IconByFeedID returns a feed icon. +func (s *Storage) IconByFeedID(userID, feedID int64) (*model.Icon, error) { + defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:IconByFeedID] userID=%d, feedID=%d", userID, feedID)) + query := ` + SELECT + icons.id, icons.hash, icons.mime_type, icons.content + FROM icons + LEFT JOIN feed_icons ON feed_icons.icon_id=icons.id + LEFT JOIN feeds ON feeds.id=feed_icons.feed_id + WHERE feeds.user_id=$1 AND feeds.id=$2 + LIMIT 1 + ` + + var icon model.Icon + err := s.db.QueryRow(query, userID, feedID).Scan(&icon.ID, &icon.Hash, &icon.MimeType, &icon.Content) + if err != nil { + return nil, fmt.Errorf("unable to fetch icon: %v", err) + } + + return &icon, nil +} + // IconByHash returns an icon by the hash (checksum). func (s *Storage) IconByHash(icon *model.Icon) error { defer helper.ExecutionTime(time.Now(), "[Storage:IconByHash]") |