mirror of
https://github.com/miniflux/v2.git
synced 2025-08-01 17:38: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
df8bc742fb
5 changed files with 149 additions and 17 deletions
|
@ -210,6 +210,7 @@ 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()
|
||||
|
@ -727,6 +728,39 @@ 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", `default-src 'self'`)
|
||||
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 {
|
||||
|
@ -827,6 +861,14 @@ func move(stream Stream, destination Stream, store *storage.Storage, userID int6
|
|||
return store.UpdateFeed(feed)
|
||||
}
|
||||
|
||||
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)
|
||||
} else {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func (h *handler) editSubscriptionHandler(w http.ResponseWriter, r *http.Request) {
|
||||
userID := request.UserID(r)
|
||||
clientIP := request.ClientIP(r)
|
||||
|
@ -1208,6 +1250,7 @@ func (h *handler) subscriptionListHandler(w http.ResponseWriter, r *http.Request
|
|||
json.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
result.Subscriptions = make([]subscription, 0)
|
||||
for _, feed := range feeds {
|
||||
result.Subscriptions = append(result.Subscriptions, subscription{
|
||||
|
@ -1216,7 +1259,7 @@ func (h *handler) subscriptionListHandler(w http.ResponseWriter, r *http.Request
|
|||
URL: feed.FeedURL,
|
||||
Categories: []subscriptionCategory{{fmt.Sprintf(UserLabelPrefix, userID) + feed.Category.Title, feed.Category.Title, "folder"}},
|
||||
HTMLURL: feed.SiteURL,
|
||||
IconURL: "", // TODO: Icons are base64 encoded in the DB.
|
||||
IconURL: h.feedIconURL(feed),
|
||||
})
|
||||
}
|
||||
json.OK(w, r, result)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue