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