mirror of
https://github.com/nkanaev/yarr.git
synced 2025-05-24 00:33:14 +00:00
update
This commit is contained in:
parent
7cf27e0fde
commit
b7b707bd43
@ -53,13 +53,27 @@ type FeverFavicon struct {
|
|||||||
Data string `json:"data"`
|
Data string `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeFeverJSON(c *router.Context, data map[string]interface{}) {
|
func writeFeverJSON(c *router.Context, data map[string]interface{}, lastRefreshed int64) {
|
||||||
data["api_version"] = 1
|
data["api_version"] = 1
|
||||||
data["auth"] = 1
|
data["auth"] = 1
|
||||||
data["last_refreshed_on_time"] = time.Now().Unix()
|
data["last_refreshed_on_time"] = lastRefreshed
|
||||||
c.JSON(http.StatusOK, data)
|
c.JSON(http.StatusOK, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getLastRefreshedOnTime(httpStates map[int64]storage.HTTPState) int64 {
|
||||||
|
if len(httpStates) == 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
var lastRefreshed int64
|
||||||
|
for _, state := range httpStates {
|
||||||
|
if state.LastRefreshed.Unix() > lastRefreshed {
|
||||||
|
lastRefreshed = state.LastRefreshed.Unix()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return lastRefreshed
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Server) feverAuth(c *router.Context) bool {
|
func (s *Server) feverAuth(c *router.Context) bool {
|
||||||
if s.Username != "" && s.Password != "" {
|
if s.Username != "" && s.Password != "" {
|
||||||
apiKey := c.Req.FormValue("api_key")
|
apiKey := c.Req.FormValue("api_key")
|
||||||
@ -156,7 +170,7 @@ func (s *Server) feverGroupsHandler(c *router.Context) {
|
|||||||
writeFeverJSON(c, map[string]interface{}{
|
writeFeverJSON(c, map[string]interface{}{
|
||||||
"groups": groups,
|
"groups": groups,
|
||||||
"feeds_groups": feedGroups(s.db),
|
"feeds_groups": feedGroups(s.db),
|
||||||
})
|
}, getLastRefreshedOnTime(s.db.ListHTTPStates()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) feverFeedsHandler(c *router.Context) {
|
func (s *Server) feverFeedsHandler(c *router.Context) {
|
||||||
@ -182,7 +196,7 @@ func (s *Server) feverFeedsHandler(c *router.Context) {
|
|||||||
writeFeverJSON(c, map[string]interface{}{
|
writeFeverJSON(c, map[string]interface{}{
|
||||||
"feeds": feverFeeds,
|
"feeds": feverFeeds,
|
||||||
"feeds_groups": feedGroups(s.db),
|
"feeds_groups": feedGroups(s.db),
|
||||||
})
|
}, getLastRefreshedOnTime(httpStates))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) feverFaviconsHandler(c *router.Context) {
|
func (s *Server) feverFaviconsHandler(c *router.Context) {
|
||||||
@ -203,7 +217,7 @@ func (s *Server) feverFaviconsHandler(c *router.Context) {
|
|||||||
|
|
||||||
writeFeverJSON(c, map[string]interface{}{
|
writeFeverJSON(c, map[string]interface{}{
|
||||||
"favicons": favicons,
|
"favicons": favicons,
|
||||||
})
|
}, getLastRefreshedOnTime(s.db.ListHTTPStates()))
|
||||||
}
|
}
|
||||||
|
|
||||||
// for memory pressure reasons, we only return a limited number of items
|
// for memory pressure reasons, we only return a limited number of items
|
||||||
@ -265,13 +279,13 @@ func (s *Server) feverItemsHandler(c *router.Context) {
|
|||||||
|
|
||||||
writeFeverJSON(c, map[string]interface{}{
|
writeFeverJSON(c, map[string]interface{}{
|
||||||
"items": feverItems,
|
"items": feverItems,
|
||||||
})
|
}, getLastRefreshedOnTime(s.db.ListHTTPStates()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) feverLinksHandler(c *router.Context) {
|
func (s *Server) feverLinksHandler(c *router.Context) {
|
||||||
writeFeverJSON(c, map[string]interface{}{
|
writeFeverJSON(c, map[string]interface{}{
|
||||||
"links": make([]interface{}, 0),
|
"links": make([]interface{}, 0),
|
||||||
})
|
}, getLastRefreshedOnTime(s.db.ListHTTPStates()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) feverUnreadItemIDsHandler(c *router.Context) {
|
func (s *Server) feverUnreadItemIDsHandler(c *router.Context) {
|
||||||
@ -293,7 +307,7 @@ func (s *Server) feverUnreadItemIDsHandler(c *router.Context) {
|
|||||||
}
|
}
|
||||||
writeFeverJSON(c, map[string]interface{}{
|
writeFeverJSON(c, map[string]interface{}{
|
||||||
"unread_item_ids": joinInts(itemIds),
|
"unread_item_ids": joinInts(itemIds),
|
||||||
})
|
}, getLastRefreshedOnTime(s.db.ListHTTPStates()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) feverSavedItemIDsHandler(c *router.Context) {
|
func (s *Server) feverSavedItemIDsHandler(c *router.Context) {
|
||||||
@ -315,7 +329,7 @@ func (s *Server) feverSavedItemIDsHandler(c *router.Context) {
|
|||||||
}
|
}
|
||||||
writeFeverJSON(c, map[string]interface{}{
|
writeFeverJSON(c, map[string]interface{}{
|
||||||
"saved_item_ids": joinInts(itemIds),
|
"saved_item_ids": joinInts(itemIds),
|
||||||
})
|
}, getLastRefreshedOnTime(s.db.ListHTTPStates()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) feverMarkHandler(c *router.Context) {
|
func (s *Server) feverMarkHandler(c *router.Context) {
|
||||||
@ -343,6 +357,9 @@ func (s *Server) feverMarkHandler(c *router.Context) {
|
|||||||
}
|
}
|
||||||
s.db.UpdateItemStatus(id, status)
|
s.db.UpdateItemStatus(id, status)
|
||||||
case "feed":
|
case "feed":
|
||||||
|
if c.Req.Form.Get("as") != "read" {
|
||||||
|
c.Out.WriteHeader(http.StatusBadRequest)
|
||||||
|
}
|
||||||
markFilter := storage.MarkFilter{FeedID: &id}
|
markFilter := storage.MarkFilter{FeedID: &id}
|
||||||
x, _ := strconv.ParseInt(c.Req.Form.Get("before"), 10, 64)
|
x, _ := strconv.ParseInt(c.Req.Form.Get("before"), 10, 64)
|
||||||
if x > 0 {
|
if x > 0 {
|
||||||
@ -350,8 +367,10 @@ func (s *Server) feverMarkHandler(c *router.Context) {
|
|||||||
markFilter.Before = &before
|
markFilter.Before = &before
|
||||||
}
|
}
|
||||||
s.db.MarkItemsRead(markFilter)
|
s.db.MarkItemsRead(markFilter)
|
||||||
// s.db.MarkItemsRead(markFilter)
|
|
||||||
case "group":
|
case "group":
|
||||||
|
if c.Req.Form.Get("as") != "read" {
|
||||||
|
c.Out.WriteHeader(http.StatusBadRequest)
|
||||||
|
}
|
||||||
markFilter := storage.MarkFilter{FolderID: &id}
|
markFilter := storage.MarkFilter{FolderID: &id}
|
||||||
x, _ := strconv.ParseInt(c.Req.Form.Get("before"), 10, 64)
|
x, _ := strconv.ParseInt(c.Req.Form.Get("before"), 10, 64)
|
||||||
if x > 0 {
|
if x > 0 {
|
||||||
|
@ -164,6 +164,10 @@ func listQueryPredicate(filter ItemFilter, newestFirst bool) (string, []interfac
|
|||||||
cond = append(cond, "i.id < ?")
|
cond = append(cond, "i.id < ?")
|
||||||
args = append(args, filter.MaxID)
|
args = append(args, filter.MaxID)
|
||||||
}
|
}
|
||||||
|
if filter.Before != nil {
|
||||||
|
cond = append(cond, "i.date < ?")
|
||||||
|
args = append(args, filter.Before)
|
||||||
|
}
|
||||||
|
|
||||||
predicate := "1"
|
predicate := "1"
|
||||||
if len(cond) > 0 {
|
if len(cond) > 0 {
|
||||||
@ -244,7 +248,11 @@ func (s *Storage) UpdateItemStatus(item_id int64, status ItemStatus) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Storage) MarkItemsRead(filter MarkFilter) bool {
|
func (s *Storage) MarkItemsRead(filter MarkFilter) bool {
|
||||||
predicate, args := listQueryPredicate(ItemFilter{FolderID: filter.FolderID, FeedID: filter.FeedID}, false)
|
predicate, args := listQueryPredicate(ItemFilter{
|
||||||
|
FolderID: filter.FolderID,
|
||||||
|
FeedID: filter.FeedID,
|
||||||
|
Before: filter.Before,
|
||||||
|
}, false)
|
||||||
query := fmt.Sprintf(`
|
query := fmt.Sprintf(`
|
||||||
update items as i set status = %d
|
update items as i set status = %d
|
||||||
where %s and i.status != %d
|
where %s and i.status != %d
|
||||||
|
Loading…
x
Reference in New Issue
Block a user