diff --git a/internal/googlereader/handler.go b/internal/googlereader/handler.go index 2f40f8f4..f4569380 100644 --- a/internal/googlereader/handler.go +++ b/internal/googlereader/handler.go @@ -210,7 +210,6 @@ func (r RequestModifiers) String() string { func Serve(router *mux.Router, store *storage.Storage) { handler := &handler{store, router} router.HandleFunc("/accounts/ClientLogin", handler.clientLoginHandler).Methods(http.MethodPost).Name("ClientLogin") - router.HandleFunc("/reader/api/0/icons/{externalIconID}", handler.iconHandler).Methods(http.MethodGet).Name("Icons") middleware := newMiddleware(store) sr := router.PathPrefix("/reader/api/0").Subrouter() @@ -728,39 +727,6 @@ func (h *handler) quickAddHandler(w http.ResponseWriter, r *http.Request) { }) } -func (h *handler) iconHandler(w http.ResponseWriter, r *http.Request) { - clientIP := request.ClientIP(r) - externalIconID := request.RouteStringParam(r, "externalIconID") - - slog.Debug("[GoogleReader] Handle /icons/{externalIconID}", - slog.String("handler", "iconHandler"), - slog.String("client_ip", clientIP), - slog.String("user_agent", r.UserAgent()), - slog.String("external_icon_id", externalIconID), - ) - - icon, err := h.store.IconByExternalID(externalIconID) - if err != nil { - json.ServerError(w, r, err) - return - } - - if icon == nil { - json.NotFound(w, r) - return - } - - response.New(w, r).WithCaching(icon.Hash, 72*time.Hour, func(b *response.Builder) { - b.WithHeader("Content-Security-Policy", `sandbox`) - b.WithHeader("Content-Type", icon.MimeType) - b.WithBody(icon.Content) - if icon.MimeType != "image/svg+xml" { - b.WithoutCompression() - } - b.Write() - }) -} - func getFeed(stream Stream, store *storage.Storage, userID int64) (*model.Feed, error) { feedID, err := strconv.ParseInt(stream.ID, 10, 64) if err != nil { @@ -863,7 +829,7 @@ func move(stream Stream, destination Stream, store *storage.Storage, userID int6 func (h *handler) feedIconURL(f *model.Feed) string { if f.Icon != nil && f.Icon.ExternalIconID != "" { - return config.Opts.RootURL() + route.Path(h.router, "Icons", "externalIconID", f.Icon.ExternalIconID) + return config.Opts.RootURL() + route.Path(h.router, "feedIcon", "externalIconID", f.Icon.ExternalIconID) } else { return "" } diff --git a/internal/storage/entry_query_builder.go b/internal/storage/entry_query_builder.go index e9f9692c..af9b6b1b 100644 --- a/internal/storage/entry_query_builder.go +++ b/internal/storage/entry_query_builder.go @@ -293,6 +293,7 @@ func (e *EntryQueryBuilder) GetEntries() (model.Entries, error) { f.hide_globally, f.no_media_player, fi.icon_id, + i.external_id AS icon_external_id, u.timezone FROM entries e @@ -302,6 +303,8 @@ func (e *EntryQueryBuilder) GetEntries() (model.Entries, error) { categories c ON c.id=f.category_id LEFT JOIN feed_icons fi ON fi.feed_id=f.id + LEFT JOIN + icons i ON i.id=fi.icon_id LEFT JOIN users u ON u.id=e.user_id WHERE %s %s @@ -323,6 +326,7 @@ func (e *EntryQueryBuilder) GetEntries() (model.Entries, error) { for rows.Next() { var iconID sql.NullInt64 + var externalIconID sql.NullString var tz string entry := model.NewEntry() @@ -361,6 +365,7 @@ func (e *EntryQueryBuilder) GetEntries() (model.Entries, error) { &entry.Feed.HideGlobally, &entry.Feed.NoMediaPlayer, &iconID, + &externalIconID, &tz, ) @@ -368,8 +373,10 @@ func (e *EntryQueryBuilder) GetEntries() (model.Entries, error) { return nil, fmt.Errorf("store: unable to fetch entry row: %v", err) } - if iconID.Valid { + if iconID.Valid && externalIconID.Valid && externalIconID.String != "" { + entry.Feed.Icon.FeedID = entry.FeedID entry.Feed.Icon.IconID = iconID.Int64 + entry.Feed.Icon.ExternalIconID = externalIconID.String } else { entry.Feed.Icon.IconID = 0 } diff --git a/internal/storage/icon.go b/internal/storage/icon.go index 6cc98a25..072a5239 100644 --- a/internal/storage/icon.go +++ b/internal/storage/icon.go @@ -59,7 +59,7 @@ func (s *Storage) IconByExternalID(externalIconID string) (*model.Icon, error) { 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 nil, fmt.Errorf("store: unable to fetch icon %s: %w", externalIconID, err) } return &icon, nil diff --git a/internal/template/templates/common/feed_list.html b/internal/template/templates/common/feed_list.html index e76cf624..3da5da9c 100644 --- a/internal/template/templates/common/feed_list.html +++ b/internal/template/templates/common/feed_list.html @@ -10,7 +10,7 @@