mirror of
https://github.com/nkanaev/yarr.git
synced 2025-05-25 13:39:22 +00:00
search for icons only during startup and after adding feeds
This commit is contained in:
parent
c8d6363677
commit
fa92ea16b0
@ -186,14 +186,8 @@ func (s *Server) handleFeedList(c *router.Context) {
|
|||||||
form.FolderID,
|
form.FolderID,
|
||||||
)
|
)
|
||||||
s.db.CreateItems(worker.ConvertItems(result.Feed.Items, *feed))
|
s.db.CreateItems(worker.ConvertItems(result.Feed.Items, *feed))
|
||||||
|
s.worker.FindFeedFavicon(*feed)
|
||||||
|
|
||||||
icon, err := worker.FindFavicon(feed.Link, feed.FeedLink)
|
|
||||||
if icon != nil {
|
|
||||||
s.db.UpdateFeedIcon(feed.Id, icon)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("Failed to find favicon for %s (%d): %s", feed.FeedLink, feed.Id, err)
|
|
||||||
}
|
|
||||||
c.JSON(http.StatusOK, map[string]string{"status": "success"})
|
c.JSON(http.StatusOK, map[string]string{"status": "success"})
|
||||||
default:
|
default:
|
||||||
c.JSON(http.StatusOK, map[string]string{"status": "notfound"})
|
c.JSON(http.StatusOK, map[string]string{"status": "notfound"})
|
||||||
@ -364,7 +358,9 @@ func (s *Server) handleOPMLImport(c *router.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s.worker.FindFavicons()
|
||||||
s.worker.RefreshFeeds()
|
s.worker.RefreshFeeds()
|
||||||
|
|
||||||
c.Out.WriteHeader(http.StatusOK)
|
c.Out.WriteHeader(http.StatusOK)
|
||||||
} else {
|
} else {
|
||||||
c.Out.WriteHeader(http.StatusMethodNotAllowed)
|
c.Out.WriteHeader(http.StatusMethodNotAllowed)
|
||||||
|
@ -41,6 +41,7 @@ func (h *Server) GetAddr() string {
|
|||||||
|
|
||||||
func (s *Server) Start() {
|
func (s *Server) Start() {
|
||||||
refreshRate := s.db.GetSettingsValueInt64("refresh_rate")
|
refreshRate := s.db.GetSettingsValueInt64("refresh_rate")
|
||||||
|
s.worker.FindFavicons()
|
||||||
s.worker.StartFeedCleaner()
|
s.worker.StartFeedCleaner()
|
||||||
s.worker.SetRefreshRate(refreshRate)
|
s.worker.SetRefreshRate(refreshRate)
|
||||||
if refreshRate > 0 {
|
if refreshRate > 0 {
|
||||||
|
@ -74,7 +74,7 @@ func DiscoverFeed(candidateUrl string) (*DiscoverResult, error) {
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func FindFavicon(websiteUrl, feedUrl string) (*[]byte, error) {
|
func findFavicon(websiteUrl, feedUrl string) (*[]byte, error) {
|
||||||
candidateUrls := make([]string, 0)
|
candidateUrls := make([]string, 0)
|
||||||
|
|
||||||
favicon := func(link string) string {
|
favicon := func(link string) string {
|
||||||
|
@ -37,6 +37,26 @@ func (w *Worker) StartFeedCleaner() {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *Worker) FindFavicons() {
|
||||||
|
go func() {
|
||||||
|
for _, feed := range w.db.ListFeeds() {
|
||||||
|
if !feed.HasIcon {
|
||||||
|
w.FindFeedFavicon(feed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *Worker) FindFeedFavicon(feed storage.Feed) {
|
||||||
|
icon, err := findFavicon(feed.Link, feed.FeedLink)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Failed to find favicon for %s (%s): %s", feed.FeedLink, feed.Link, err)
|
||||||
|
}
|
||||||
|
if icon != nil {
|
||||||
|
w.db.UpdateFeedIcon(feed.Id, icon)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (w *Worker) SetRefreshRate(minute int64) {
|
func (w *Worker) SetRefreshRate(minute int64) {
|
||||||
if w.stopper != nil {
|
if w.stopper != nil {
|
||||||
w.refresh.Stop()
|
w.refresh.Stop()
|
||||||
@ -116,16 +136,5 @@ func (w *Worker) worker(srcqueue <-chan storage.Feed, dstqueue chan<- []storage.
|
|||||||
w.db.SetFeedError(feed.Id, err)
|
w.db.SetFeedError(feed.Id, err)
|
||||||
}
|
}
|
||||||
dstqueue <- items
|
dstqueue <- items
|
||||||
|
|
||||||
// TODO: move somewhere else
|
|
||||||
if !feed.HasIcon {
|
|
||||||
icon, err := FindFavicon(feed.Link, feed.FeedLink)
|
|
||||||
if icon != nil {
|
|
||||||
w.db.UpdateFeedIcon(feed.Id, icon)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("Failed to find favicon for %s (%s): %s", feed.FeedLink, feed.Link, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user