Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebAPI: Do not wrap result if offset is invalid #22174

Merged
merged 3 commits into from
Feb 18, 2025

Conversation

userwiths
Copy link
Contributor

@userwiths userwiths commented Jan 17, 2025

Closes #22158.

@Chocobo1 Chocobo1 added the WebAPI WebAPI-related issues/changes label Jan 19, 2025
@glassez glassez changed the title Do not wrap API result if offset is invalid. WebAPI: Do not wrap result if offset is invalid Jan 21, 2025
@userwiths userwiths requested a review from Chocobo1 January 27, 2025 12:48
@Chocobo1 Chocobo1 added this to the 5.1 milestone Jan 27, 2025
@glassez
Copy link
Member

glassez commented Jan 27, 2025

Could you summarize how it will behave after applying this patch?

Note that in the description of the PR, it is better to indicate how it will behave after merging it than just the problem itself (the description of the problem is generally redundant if there is a corresponding Issue to which it refers).

@userwiths
Copy link
Contributor Author

Yeah sure.

I will write down a few example cases below, but the main gist is that if a (positive) limit and (whatever) offset are provided, we return a list of items that overlap offset; offset + limit and - size; size -1 where - size and 0 are the first torrent and size-1 is the last one. If there is no overlap, we return an empty list.

If (negative) limit is provided we return a list of all torrents with index > offset (if offset is negative or 0 that is all torrents, if its 0 < offset < size - 1 we return all with index > offset and if offset > size we return an empty list.

So ... lets say we have 5 torrents.

limit=1&offset=0 => returns the first torrent.
limit=1&offset=4 => returns the last torrent.
limit=1&offset=5 => returns empty list [].
limit=1&offset=-1 => returns last torrent.
limit=1&offset=-5 => returns the first torrent.
limit=1&offset=-6 => returns empty list [].
limit=2&offset=-6 => returns the first torrent.
limit=3&offset=-6 => returns first two torrents.
offset=-6 => returns all available torrents.
offset=6 => returns empty list [].

Hope this explanation is good enough .

@glassez

This comment was marked as resolved.

@userwiths

This comment was marked as resolved.

@glassez

This comment was marked as resolved.

@Chocobo1 Chocobo1 merged commit ad9100a into qbittorrent:master Feb 18, 2025
15 checks passed
@Chocobo1
Copy link
Member

@userwiths
Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WebAPI WebAPI-related issues/changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Results wrap when using limit+offset on torrents/info API
3 participants