fix(jellyfin): page the user-root /Items libraries by StartIndex and Limit

This commit is contained in:
zapisanchez 2026-10-06 15:13:19 +02:00
commit c9ba02777a
2 changed files with 15 additions and 1 deletions

View file

@ -428,7 +428,8 @@ func (api *Router) queryItems(ctx context.Context, r *http.Request) (itemsResult
if err != nil {
return itemsResult{}, err
}
return materialized(result(views, len(views), 0)), nil
offset := max(q.offset, 0)
return materialized(result(paginate(views, offset, q.limit), len(views), offset)), nil
}
if repo, ok := api.playlistTracksRepo(ctx, q); ok {
return api.playlistTrackPage(ctx, repo, q.fields, q.offset, q.limit)

View file

@ -69,6 +69,19 @@ var _ = Describe("Items", func() {
Expect(res.Items[0].CollectionType).To(Equal("music"))
})
It("pages the libraries by StartIndex and Limit", func() {
w := httptest.NewRecorder()
r := httptest.NewRequest("GET", "/Items?StartIndex=1&Limit=1", nil).
WithContext(ctxUserWithLibraries(model.Libraries{{ID: 1, Name: "Music"}, {ID: 2, Name: "Other"}}))
invoke(api.getItems, w, r)
var res dto.QueryResult
Expect(json.Unmarshal(w.Body.Bytes(), &res)).To(Succeed())
Expect(res.TotalRecordCount).To(Equal(2))
Expect(res.StartIndex).To(Equal(1))
Expect(res.Items).To(HaveLen(1))
Expect(res.Items[0].Id).To(Equal(dto.EncodeLibraryID(2)))
})
It("treats an unknown IncludeItemTypes as absent", func() {
w := httptest.NewRecorder()
r := httptest.NewRequest("GET", "/Items?IncludeItemTypes=music", nil).WithContext(ctxUser())