mirror of
https://github.com/nkanaev/yarr.git
synced 2025-05-24 00:33:14 +00:00
fever favicons endpoint
This commit is contained in:
parent
a13aea478e
commit
57d2437e9c
@ -5,6 +5,7 @@ import (
|
|||||||
"github.com/nkanaev/yarr/storage"
|
"github.com/nkanaev/yarr/storage"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
"encoding/base64"
|
||||||
)
|
)
|
||||||
|
|
||||||
var feverHandlers = map[string]func(rw http.ResponseWriter, req *http.Request){
|
var feverHandlers = map[string]func(rw http.ResponseWriter, req *http.Request){
|
||||||
@ -39,6 +40,11 @@ type FeverFeed struct {
|
|||||||
LastUpdatedOnTime int64 `json:"last_updated_on_time"`
|
LastUpdatedOnTime int64 `json:"last_updated_on_time"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type FeverFavicon struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
Data string `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
func writeFeverJSON(rw http.ResponseWriter, data map[string]interface{}) {
|
func writeFeverJSON(rw http.ResponseWriter, data map[string]interface{}) {
|
||||||
data["api_version"] = 1
|
data["api_version"] = 1
|
||||||
data["auth"] = 1
|
data["auth"] = 1
|
||||||
@ -157,7 +163,24 @@ func FeverFilteredItemIDsHandler(rw http.ResponseWriter, req *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func FeverFaviconsHandler(rw http.ResponseWriter, req *http.Request) {
|
func FeverFaviconsHandler(rw http.ResponseWriter, req *http.Request) {
|
||||||
|
feeds := db(req).ListFeeds()
|
||||||
|
favicons := make([]*FeverFavicon, len(feeds))
|
||||||
|
for i, feed := range feeds {
|
||||||
|
data := "data:image/gif;base64,R0lGODlhAQABAAAAACw="
|
||||||
|
if feed.HasIcon {
|
||||||
|
icon := db(req).GetFeed(feed.Id).Icon
|
||||||
|
data = fmt.Sprintf(
|
||||||
|
"data:%s;base64,%s",
|
||||||
|
http.DetectContentType(*icon),
|
||||||
|
base64.StdEncoding.EncodeToString(*icon),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
favicons[i] = &FeverFavicon{ID: feed.Id, Data: data}
|
||||||
|
}
|
||||||
|
|
||||||
|
writeFeverJSON(rw, map[string]interface{}{
|
||||||
|
"favicons": favicons,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func FeverItemsHandler(rw http.ResponseWriter, req *http.Request) {
|
func FeverItemsHandler(rw http.ResponseWriter, req *http.Request) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user