2017-12-16 14:25:18 -05: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.
|
|
|
|
|
2018-08-25 00:51:50 -04:00
|
|
|
package api // import "miniflux.app/api"
|
2017-12-16 14:25:18 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2018-04-29 19:35:04 -04:00
|
|
|
"net/http"
|
2017-12-16 14:25:18 -05:00
|
|
|
|
2018-08-25 00:51:50 -04:00
|
|
|
"miniflux.app/http/context"
|
|
|
|
"miniflux.app/http/request"
|
|
|
|
"miniflux.app/http/response/json"
|
2017-12-16 14:25:18 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// FeedIcon returns a feed icon.
|
2018-04-29 19:35:04 -04:00
|
|
|
func (c *Controller) FeedIcon(w http.ResponseWriter, r *http.Request) {
|
|
|
|
feedID, err := request.IntParam(r, "feedID")
|
2017-12-16 14:25:18 -05:00
|
|
|
if err != nil {
|
2018-04-29 19:35:04 -04:00
|
|
|
json.BadRequest(w, err)
|
2017-12-16 14:25:18 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if !c.store.HasIcon(feedID) {
|
2018-04-29 19:35:04 -04:00
|
|
|
json.NotFound(w, errors.New("This feed doesn't have any icon"))
|
2017-12-16 14:25:18 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-04-29 19:35:04 -04:00
|
|
|
icon, err := c.store.IconByFeedID(context.New(r).UserID(), feedID)
|
2017-12-16 14:25:18 -05:00
|
|
|
if err != nil {
|
2018-04-29 19:35:04 -04:00
|
|
|
json.ServerError(w, errors.New("Unable to fetch feed icon"))
|
2017-12-16 14:25:18 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if icon == nil {
|
2018-04-29 19:35:04 -04:00
|
|
|
json.NotFound(w, errors.New("This feed doesn't have any icon"))
|
2017-12-16 14:25:18 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-07-19 22:27:05 -04:00
|
|
|
json.OK(w, r, &feedIcon{
|
2017-12-16 14:25:18 -05:00
|
|
|
ID: icon.ID,
|
|
|
|
MimeType: icon.MimeType,
|
|
|
|
Data: icon.DataURL(),
|
|
|
|
})
|
|
|
|
}
|