2017-12-16 20:25:18 +01:00
|
|
|
// Copyright 2017 Frédéric Guillot. All rights reserved.
|
|
|
|
// Use of this source code is governed by the Apache 2.0
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2018-04-30 01:35:04 +02:00
|
|
|
"net/http"
|
2017-12-16 20:25:18 +01:00
|
|
|
|
2018-04-30 01:35:04 +02:00
|
|
|
"github.com/miniflux/miniflux/http/context"
|
|
|
|
"github.com/miniflux/miniflux/http/request"
|
|
|
|
"github.com/miniflux/miniflux/http/response/json"
|
2017-12-16 20:25:18 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// FeedIcon returns a feed icon.
|
2018-04-30 01:35:04 +02:00
|
|
|
func (c *Controller) FeedIcon(w http.ResponseWriter, r *http.Request) {
|
|
|
|
feedID, err := request.IntParam(r, "feedID")
|
2017-12-16 20:25:18 +01:00
|
|
|
if err != nil {
|
2018-04-30 01:35:04 +02:00
|
|
|
json.BadRequest(w, err)
|
2017-12-16 20:25:18 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if !c.store.HasIcon(feedID) {
|
2018-04-30 01:35:04 +02:00
|
|
|
json.NotFound(w, errors.New("This feed doesn't have any icon"))
|
2017-12-16 20:25:18 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-04-30 01:35:04 +02:00
|
|
|
icon, err := c.store.IconByFeedID(context.New(r).UserID(), feedID)
|
2017-12-16 20:25:18 +01:00
|
|
|
if err != nil {
|
2018-04-30 01:35:04 +02:00
|
|
|
json.ServerError(w, errors.New("Unable to fetch feed icon"))
|
2017-12-16 20:25:18 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if icon == nil {
|
2018-04-30 01:35:04 +02:00
|
|
|
json.NotFound(w, errors.New("This feed doesn't have any icon"))
|
2017-12-16 20:25:18 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-04-30 01:35:04 +02:00
|
|
|
json.OK(w, &feedIcon{
|
2017-12-16 20:25:18 +01:00
|
|
|
ID: icon.ID,
|
|
|
|
MimeType: icon.MimeType,
|
|
|
|
Data: icon.DataURL(),
|
|
|
|
})
|
|
|
|
}
|