2023-06-19 14:42:47 -07:00
|
|
|
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2017-12-16 11:25:18 -08:00
|
|
|
|
2023-08-10 19:46:45 -07:00
|
|
|
package api // import "miniflux.app/v2/internal/api"
|
2017-12-16 11:25:18 -08:00
|
|
|
|
|
|
|
import (
|
2018-04-29 16:35:04 -07:00
|
|
|
"net/http"
|
2017-12-16 11:25:18 -08:00
|
|
|
|
2023-08-10 19:46:45 -07:00
|
|
|
"miniflux.app/v2/internal/http/request"
|
|
|
|
"miniflux.app/v2/internal/http/response/json"
|
2017-12-16 11:25:18 -08:00
|
|
|
)
|
|
|
|
|
2023-10-05 22:23:29 -07:00
|
|
|
func (h *handler) getIconByFeedID(w http.ResponseWriter, r *http.Request) {
|
2018-09-23 21:02:26 -07:00
|
|
|
feedID := request.RouteInt64Param(r, "feedID")
|
2017-12-16 11:25:18 -08:00
|
|
|
|
2018-11-11 10:22:47 -08:00
|
|
|
if !h.store.HasIcon(feedID) {
|
2018-10-07 18:42:43 -07:00
|
|
|
json.NotFound(w, r)
|
2017-12-16 11:25:18 -08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-11-11 10:22:47 -08:00
|
|
|
icon, err := h.store.IconByFeedID(request.UserID(r), feedID)
|
2017-12-16 11:25:18 -08:00
|
|
|
if err != nil {
|
2018-10-07 18:42:43 -07:00
|
|
|
json.ServerError(w, r, err)
|
2017-12-16 11:25:18 -08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if icon == nil {
|
2018-10-07 18:42:43 -07:00
|
|
|
json.NotFound(w, r)
|
2017-12-16 11:25:18 -08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-12-13 20:31:19 -08:00
|
|
|
json.OK(w, r, &feedIconResponse{
|
2017-12-16 11:25:18 -08:00
|
|
|
ID: icon.ID,
|
|
|
|
MimeType: icon.MimeType,
|
|
|
|
Data: icon.DataURL(),
|
|
|
|
})
|
|
|
|
}
|
2023-10-05 22:23:29 -07:00
|
|
|
|
|
|
|
func (h *handler) getIconByIconID(w http.ResponseWriter, r *http.Request) {
|
|
|
|
iconID := request.RouteInt64Param(r, "iconID")
|
|
|
|
|
|
|
|
icon, err := h.store.IconByID(iconID)
|
|
|
|
if err != nil {
|
|
|
|
json.ServerError(w, r, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if icon == nil {
|
|
|
|
json.NotFound(w, r)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
json.OK(w, r, &feedIconResponse{
|
|
|
|
ID: icon.ID,
|
|
|
|
MimeType: icon.MimeType,
|
|
|
|
Data: icon.DataURL(),
|
|
|
|
})
|
|
|
|
}
|