diff options
| author | Samantaz Fox <coding@samantaz.fr> | 2024-07-21 17:07:46 +0200 |
|---|---|---|
| committer | Samantaz Fox <coding@samantaz.fr> | 2024-07-21 17:24:01 +0200 |
| commit | 4f60feee1701b41d3778a7bbc358a9b1c372949e (patch) | |
| tree | 074a3823a3b65eca5aa75d371d0294946e1fb3f6 | |
| parent | 733bd27a5cfe3583576f9e306152cfae1720a051 (diff) | |
| parent | e0d0dbde3cd1cba313d990244977a890a32976de (diff) | |
| download | invidious-4f60feee1701b41d3778a7bbc358a9b1c372949e.tar.gz invidious-4f60feee1701b41d3778a7bbc358a9b1c372949e.tar.bz2 invidious-4f60feee1701b41d3778a7bbc358a9b1c372949e.zip | |
API: Fix out of bound error on empty playlists (#4696)
Before this PR, Invidious assumed that every playlist had at least one video.
When a playlist had no videos, Invidious was throwing an "Index out of bounds"
exception.
The following API endpoints were impacted:
* api/v1/playlists/:plid
* api/v1/auth/playlists/:plid
Fixes issue 4679
| -rw-r--r-- | src/invidious/routes/api/v1/misc.cr | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/invidious/routes/api/v1/misc.cr b/src/invidious/routes/api/v1/misc.cr index 12942906..0c79692d 100644 --- a/src/invidious/routes/api/v1/misc.cr +++ b/src/invidious/routes/api/v1/misc.cr @@ -74,7 +74,9 @@ module Invidious::Routes::API::V1::Misc response = playlist.to_json(offset, video_id: video_id) json_response = JSON.parse(response) - if json_response["videos"].as_a[0]["index"] != offset + if json_response["videos"].as_a.empty? + json_response = JSON.parse(response) + elsif json_response["videos"].as_a[0]["index"] != offset offset = json_response["videos"].as_a[0]["index"].as_i lookback = offset < 50 ? offset : 50 response = playlist.to_json(offset - lookback) |
