mirror of
https://github.com/miniflux/v2.git
synced 2025-07-22 17:18:37 +00:00
feat(googlereader): add feed icon field, endpoint
Adds an endpoint to the Google Reader integration to serve feed icon URLs.
This commit is contained in:
parent
e342a4f143
commit
a3148dbed9
5 changed files with 149 additions and 17 deletions
|
@ -8,6 +8,7 @@ import (
|
|||
"fmt"
|
||||
"strings"
|
||||
|
||||
"miniflux.app/v2/internal/crypto"
|
||||
"miniflux.app/v2/internal/model"
|
||||
)
|
||||
|
||||
|
@ -22,8 +23,16 @@ func (s *Storage) HasFeedIcon(feedID int64) bool {
|
|||
// IconByID returns an icon by the ID.
|
||||
func (s *Storage) IconByID(iconID int64) (*model.Icon, error) {
|
||||
var icon model.Icon
|
||||
query := `SELECT id, hash, mime_type, content FROM icons WHERE id=$1`
|
||||
err := s.db.QueryRow(query, iconID).Scan(&icon.ID, &icon.Hash, &icon.MimeType, &icon.Content)
|
||||
query := `
|
||||
SELECT
|
||||
id,
|
||||
hash,
|
||||
mime_type,
|
||||
content,
|
||||
external_id
|
||||
FROM icons
|
||||
WHERE id=$1`
|
||||
err := s.db.QueryRow(query, iconID).Scan(&icon.ID, &icon.Hash, &icon.MimeType, &icon.Content, &icon.ExternalID)
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, nil
|
||||
} else if err != nil {
|
||||
|
@ -33,6 +42,29 @@ func (s *Storage) IconByID(iconID int64) (*model.Icon, error) {
|
|||
return &icon, nil
|
||||
}
|
||||
|
||||
// IconByExternalID returns an icon by the External Icon ID.
|
||||
func (s *Storage) IconByExternalID(externalIconID string) (*model.Icon, error) {
|
||||
var icon model.Icon
|
||||
query := `
|
||||
SELECT
|
||||
id,
|
||||
hash,
|
||||
mime_type,
|
||||
content,
|
||||
external_id
|
||||
FROM icons
|
||||
WHERE external_id=$1
|
||||
`
|
||||
err := s.db.QueryRow(query, externalIconID).Scan(&icon.ID, &icon.Hash, &icon.MimeType, &icon.Content, &icon.ExternalID)
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, nil
|
||||
} else if err != nil {
|
||||
return nil, fmt.Errorf("store: unable to fetch icon #%s: %w", externalIconID, err)
|
||||
}
|
||||
|
||||
return &icon, nil
|
||||
}
|
||||
|
||||
// IconByFeedID returns a feed icon.
|
||||
func (s *Storage) IconByFeedID(userID, feedID int64) (*model.Icon, error) {
|
||||
query := `
|
||||
|
@ -40,7 +72,8 @@ func (s *Storage) IconByFeedID(userID, feedID int64) (*model.Icon, error) {
|
|||
icons.id,
|
||||
icons.hash,
|
||||
icons.mime_type,
|
||||
icons.content
|
||||
icons.content,
|
||||
icons.external_id
|
||||
FROM icons
|
||||
LEFT JOIN feed_icons ON feed_icons.icon_id=icons.id
|
||||
LEFT JOIN feeds ON feeds.id=feed_icons.feed_id
|
||||
|
@ -49,7 +82,7 @@ func (s *Storage) IconByFeedID(userID, feedID int64) (*model.Icon, error) {
|
|||
LIMIT 1
|
||||
`
|
||||
var icon model.Icon
|
||||
err := s.db.QueryRow(query, userID, feedID).Scan(&icon.ID, &icon.Hash, &icon.MimeType, &icon.Content)
|
||||
err := s.db.QueryRow(query, userID, feedID).Scan(&icon.ID, &icon.Hash, &icon.MimeType, &icon.Content, &icon.ExternalID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf(`store: unable to fetch icon: %v`, err)
|
||||
}
|
||||
|
@ -67,9 +100,9 @@ func (s *Storage) StoreFeedIcon(feedID int64, icon *model.Icon) error {
|
|||
if err := tx.QueryRow(`SELECT id FROM icons WHERE hash=$1`, icon.Hash).Scan(&icon.ID); err == sql.ErrNoRows {
|
||||
query := `
|
||||
INSERT INTO icons
|
||||
(hash, mime_type, content)
|
||||
(hash, mime_type, content, external_id)
|
||||
VALUES
|
||||
($1, $2, $3)
|
||||
($1, $2, $3, $4)
|
||||
RETURNING
|
||||
id
|
||||
`
|
||||
|
@ -78,6 +111,7 @@ func (s *Storage) StoreFeedIcon(feedID int64, icon *model.Icon) error {
|
|||
icon.Hash,
|
||||
normalizeMimeType(icon.MimeType),
|
||||
icon.Content,
|
||||
crypto.GenerateRandomStringHex(20),
|
||||
).Scan(&icon.ID)
|
||||
|
||||
if err != nil {
|
||||
|
@ -113,7 +147,8 @@ func (s *Storage) Icons(userID int64) (model.Icons, error) {
|
|||
icons.id,
|
||||
icons.hash,
|
||||
icons.mime_type,
|
||||
icons.content
|
||||
icons.content,
|
||||
icons.external_id
|
||||
FROM icons
|
||||
LEFT JOIN feed_icons ON feed_icons.icon_id=icons.id
|
||||
LEFT JOIN feeds ON feeds.id=feed_icons.feed_id
|
||||
|
@ -129,7 +164,7 @@ func (s *Storage) Icons(userID int64) (model.Icons, error) {
|
|||
var icons model.Icons
|
||||
for rows.Next() {
|
||||
var icon model.Icon
|
||||
err := rows.Scan(&icon.ID, &icon.Hash, &icon.MimeType, &icon.Content)
|
||||
err := rows.Scan(&icon.ID, &icon.Hash, &icon.MimeType, &icon.Content, &icon.ExternalID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf(`store: unable to fetch icons row: %v`, err)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue