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