1
0
Fork 0

Google Reader API: Take ExcludeTargets into consideration in Feed stream handler

This commit is contained in:
Frédéric Guillot 2023-11-08 16:08:44 +00:00
parent ba65556eac
commit aa3dc574a7

View file

@ -123,24 +123,14 @@ const (
LikeStream LikeStream
) )
// Stream defines a stream type and its id // Stream defines a stream type and its ID.
type Stream struct { type Stream struct {
Type StreamType Type StreamType
ID string ID string
} }
// RequestModifiers are the parsed request parameters func (s Stream) String() string {
type RequestModifiers struct { return fmt.Sprintf("%v - '%s'", s.Type, s.ID)
ExcludeTargets []Stream
FilterTargets []Stream
Streams []Stream
Count int
Offset int
SortDirection string
StartTime int64
StopTime int64
ContinuationToken string
UserID int64
} }
func (st StreamType) String() string { func (st StreamType) String() string {
@ -170,34 +160,51 @@ func (st StreamType) String() string {
} }
} }
func (s Stream) String() string { // RequestModifiers are the parsed request parameters.
return fmt.Sprintf("%v - '%s'", s.Type, s.ID) type RequestModifiers struct {
ExcludeTargets []Stream
FilterTargets []Stream
Streams []Stream
Count int
Offset int
SortDirection string
StartTime int64
StopTime int64
ContinuationToken string
UserID int64
} }
func (r RequestModifiers) String() string { func (r RequestModifiers) String() string {
result := fmt.Sprintf("UserID: %d\n", r.UserID) var results []string
result += fmt.Sprintf("Streams: %d\n", len(r.Streams))
results = append(results, fmt.Sprintf("UserID: %d", r.UserID))
var streamStr []string
for _, s := range r.Streams { for _, s := range r.Streams {
result += fmt.Sprintf(" %v\n", s) streamStr = append(streamStr, s.String())
} }
results = append(results, fmt.Sprintf("Streams: [%s]", strings.Join(streamStr, ", ")))
result += fmt.Sprintf("Exclusions: %d\n", len(r.ExcludeTargets)) var exclusions []string
for _, s := range r.ExcludeTargets { for _, s := range r.ExcludeTargets {
result += fmt.Sprintf(" %v\n", s) exclusions = append(exclusions, s.String())
} }
results = append(results, fmt.Sprintf("Exclusions: [%s]", strings.Join(exclusions, ", ")))
result += fmt.Sprintf("Filter: %d\n", len(r.FilterTargets)) var filters []string
for _, s := range r.FilterTargets { for _, s := range r.FilterTargets {
result += fmt.Sprintf(" %v\n", s) filters = append(filters, s.String())
} }
result += fmt.Sprintf("Count: %d\n", r.Count) results = append(results, fmt.Sprintf("Filters: [%s]", strings.Join(filters, ", ")))
result += fmt.Sprintf("Offset: %d\n", r.Offset)
result += fmt.Sprintf("Sort Direction: %s\n", r.SortDirection)
result += fmt.Sprintf("Continuation Token: %s\n", r.ContinuationToken)
result += fmt.Sprintf("Start Time: %d\n", r.StartTime)
result += fmt.Sprintf("Stop Time: %d\n", r.StopTime)
return result results = append(results, fmt.Sprintf("Count: %d", r.Count))
results = append(results, fmt.Sprintf("Offset: %d", r.Offset))
results = append(results, fmt.Sprintf("Sort Direction: %s", r.SortDirection))
results = append(results, fmt.Sprintf("Continuation Token: %s", r.ContinuationToken))
results = append(results, fmt.Sprintf("Start Time: %d", r.StartTime))
results = append(results, fmt.Sprintf("Stop Time: %d", r.StopTime))
return strings.Join(results, "; ")
} }
// Serve handles Google Reader API calls. // Serve handles Google Reader API calls.
@ -1279,7 +1286,7 @@ func (h *handler) streamItemIDsHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
slog.Debug("[GoogleReader] Request modifiers", slog.Debug("[GoogleReader] Request Modifiers",
slog.String("handler", "streamItemIDsHandler"), slog.String("handler", "streamItemIDsHandler"),
slog.String("client_ip", clientIP), slog.String("client_ip", clientIP),
slog.String("user_agent", r.UserAgent()), slog.String("user_agent", r.UserAgent()),
@ -1458,18 +1465,30 @@ func (h *handler) handleFeedStreamHandler(w http.ResponseWriter, r *http.Request
builder.WithLimit(rm.Count) builder.WithLimit(rm.Count)
builder.WithOffset(rm.Offset) builder.WithOffset(rm.Offset)
builder.WithSorting(model.DefaultSortingOrder, rm.SortDirection) builder.WithSorting(model.DefaultSortingOrder, rm.SortDirection)
if rm.StartTime > 0 { if rm.StartTime > 0 {
builder.AfterPublishedDate(time.Unix(rm.StartTime, 0)) builder.AfterPublishedDate(time.Unix(rm.StartTime, 0))
} }
if rm.StopTime > 0 { if rm.StopTime > 0 {
builder.BeforePublishedDate(time.Unix(rm.StopTime, 0)) builder.BeforePublishedDate(time.Unix(rm.StopTime, 0))
} }
if len(rm.ExcludeTargets) > 0 {
for _, s := range rm.ExcludeTargets {
switch s.Type {
case ReadStream:
builder.WithoutStatus(model.EntryStatusRead)
}
}
}
rawEntryIDs, err := builder.GetEntryIDs() rawEntryIDs, err := builder.GetEntryIDs()
if err != nil { if err != nil {
json.ServerError(w, r, err) json.ServerError(w, r, err)
return return
} }
var itemRefs = make([]itemRef, 0) var itemRefs = make([]itemRef, 0)
for _, entryID := range rawEntryIDs { for _, entryID := range rawEntryIDs {
formattedID := strconv.FormatInt(entryID, 10) formattedID := strconv.FormatInt(entryID, 10)
@ -1481,6 +1500,7 @@ func (h *handler) handleFeedStreamHandler(w http.ResponseWriter, r *http.Request
json.ServerError(w, r, err) json.ServerError(w, r, err)
return return
} }
continuation := 0 continuation := 0
if len(itemRefs)+rm.Offset < totalEntries { if len(itemRefs)+rm.Offset < totalEntries {
continuation = len(itemRefs) + rm.Offset continuation = len(itemRefs) + rm.Offset