From ad266e45ca6d3c19d340f65778c6c8973c143ff8 Mon Sep 17 00:00:00 2001 From: Dave Marquard Date: Thu, 31 Mar 2022 08:22:03 -0700 Subject: [PATCH] add support for feed streams to Reader API IDs API --- googlereader/handler.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/googlereader/handler.go b/googlereader/handler.go index 40f52790..bd272246 100644 --- a/googlereader/handler.go +++ b/googlereader/handler.go @@ -1096,6 +1096,8 @@ func (h *handler) streamItemIDs(w http.ResponseWriter, r *http.Request) { h.handleStarredStream(w, r, rm) case ReadStream: h.handleReadStream(w, r, rm) + case FeedStream: + h.handleFeedStream(w, r, rm) default: dump, _ := httputil.DumpRequest(r, true) logger.Info("[GoogleReader][/stream/items/ids] [ClientIP=%s] Unknown Stream: %s", clientIP, dump) @@ -1184,3 +1186,38 @@ func (h *handler) handleReadStream(w http.ResponseWriter, r *http.Request, rm Re } json.OK(w, r, streamIDResponse{itemRefs}) } + +func (h *handler) handleFeedStream(w http.ResponseWriter, r *http.Request, rm RequestModifiers) { + clientIP := request.ClientIP(r) + feedID, err := strconv.ParseInt(rm.Streams[0].ID, 10, 64) + if err != nil { + logger.Error("[GoogleReader][/stream/items/ids#feed] [ClientIP=%s] %v", clientIP, err) + json.ServerError(w, r, err) + return + } + + builder := h.store.NewEntryQueryBuilder(rm.UserID) + builder.WithFeedID(feedID) + builder.WithLimit(rm.Count) + builder.WithOrder(model.DefaultSortingOrder) + builder.WithDirection(rm.SortDirection) + if rm.StartTime > 0 { + builder.AfterDate(time.Unix(rm.StartTime, 0)) + } + if rm.StopTime > 0 { + builder.BeforeDate(time.Unix(rm.StopTime, 0)) + } + + rawEntryIDs, err := builder.GetEntryIDs() + if err != nil { + logger.Error("[GoogleReader][/stream/items/ids#starred] [ClientIP=%s] %v", clientIP, err) + json.ServerError(w, r, err) + return + } + var itemRefs = make([]itemRef, 0) + for _, entryID := range rawEntryIDs { + formattedID := strconv.FormatInt(entryID, 10) + itemRefs = append(itemRefs, itemRef{ID: formattedID}) + } + json.OK(w, r, streamIDResponse{itemRefs}) +}