1
0
Fork 0

add support for feed streams to Reader API IDs API

This commit is contained in:
Dave Marquard 2022-03-31 08:22:03 -07:00 committed by Frédéric Guillot
parent f6825c1c60
commit ad266e45ca

View file

@ -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})
}